2012-07-26 56 views
2

斯卡拉2.8.2具有Seq.apply方法,讓你可以寫在REPL如下:Seq.apply在Scala 2.9.2中去了哪裏?

val l = Seq(1, 2) 
l: Seq[In] = List(1, 2) 

這仍然工作在斯卡拉2.9.2,但令我百思不解的是,根據文檔,再也沒有像scala.collection.Seq.apply這樣的東西了。

我使用Scala -Xprint檢查:打字員,這就是它打印:

[[syntax trees at end of typer]]// Scala source: <console> 
package $line14 { 
    final object $read extends java.lang.Object with ScalaObject { 
    def this(): object $line14.$read = { 
     $read.super.this(); 
    () 
    }; 
    final object $iw extends java.lang.Object with ScalaObject { 
     def this(): object $line14.$read.$iw = { 
     $iw.super.this(); 
     () 
     }; 
     final object $iw extends java.lang.Object with ScalaObject { 
     def this(): object $line14.$read.$iw.$iw = { 
      $iw.super.this(); 
     () 
     }; 
     private[this] val l: Seq[Int] = collection.this.Seq.apply[Int](1, 2); 
     <stable> <accessor> def l: Seq[Int] = $iw.this.l 
     } 
    } 
    } 
} 

[[syntax trees at end of typer]]// Scala source: <console> 
package $line14 { 
    final object $eval extends java.lang.Object with ScalaObject { 
    def this(): object $line14.$eval = { 
     $eval.super.this(); 
    () 
    }; 
    lazy private[this] var $result: Seq[Int] = { 
     $eval.this.$print; 
     $line14.$read.$iw.$iw.l 
    }; 
    private[this] val $print: String = { 
     $read.$iw.$iw; 
     "l: Seq[Int] = ".+(scala.runtime.ScalaRunTime.replStringOf($line14.$read.$iw.$iw.l, 1000)) 
    }; 
    <stable> <accessor> def $print: String = $eval.this.$print 
    } 
} 

l: Seq[Int] = List(1, 2) 

所以結果是有效的:

collection.this.Seq.apply[Int](1, 2) 

這表明它仍然呼籲Seq.apply,但這種方法在哪裏?

+5

這是ScalaDoc一個錯誤,這是在2.10得到解決。 – sschaef 2012-07-26 11:52:37

+0

@sschaef:+1,值得成爲一個全面的答案 – 2012-07-26 11:55:41

+0

我再也找不到問題了 - >答案不夠 – sschaef 2012-07-26 11:57:00

回答

4

這實際上是Scaladoc 2.9.2中的一個bug。

我已經檢查了階-library.jar,發現伴隨對象scala.collection.Seq間接延伸scala.collection.generic.GenericCompanion [SEQ],這有效地提供了該方法的簽名:

def apply[A](elems: A*): Seq[A] 

這反過來調用newBuilder,這是在序列覆蓋,以返回:

scala.collection.immutable.Seq.newBuilder[A]