Scala 2.8.2 有一个 Seq.apply 方法,因此您可以在 REPL 中编写以下内容:
val l = Seq(1, 2)
l: Seq[In] = List(1, 2)
这在 Scala 2.9.2 中仍然有效,但令我困惑的是,根据文档,不再存在 scala.collection.Seq.apply 方法。
我检查了 scala -Xprint:typer 这就是它打印的内容:
[[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,但是这个方法在哪里呢?