我写了一小段Scala
object SquareNumbers extends App {
val numbers = List(1,2,3,4,5)
val squares = numbers map (i => i * i)
println (squares)
}然后在scalac中运行,如下所示:
$ scalac -Xprint:typer SquareNumbers.scala
[[syntax trees at end of typer]] // SquareNumbers.scala
package <empty> {
object SquareNumbers extends Object with App {
def <init>(): SquareNumbers.type = {
SquareNumbers.super.<init>();
()
};
private[this] val numbers: List[Int] = immutable.this.List.apply[Int](1, 2, 3, 4, 5);
<stable> <accessor> def numbers: List[Int] = SquareNumbers.this.numbers;
private[this] val squares: List[Int] = SquareNumbers.this.numbers.map[Int, List[Int]](((i: Int) => i.*(i)))(immutable.this.List.canBuildFrom[Int]);
<stable> <accessor> def squares: List[Int] = SquareNumbers.this.squares;
scala.this.Predef.println(SquareNumbers.this.squares)
}
}我的问题是,输出中的<stable>和<accessor>是什么?他们被称为什么(如,他们有一个集体名词),他们是做什么的?
据我猜测,这意味着它们是vars而不是vars,这意味着它是可以从物体外部调用的.
发布于 2013-08-02 20:10:38
这些是内部的(即,没有通过新的2.10反射API公开)标志。官方编译器ScalaDoc站点似乎已经关闭,但是您可以看到详细信息的Scala源代码
final val STABLE = 1 << 22 // functions that are assumed to be stable
// (typically, access methods for valdefs)
// or classes that do not contain abstract types.final val ACCESSOR = 1 << 27 // a value or variable accessor (getter or setter)在该文件的后面,您可以找到标识符(例如STABLE)和打印字符串(<stable>)之间的映射,以及在哪个阶段显示哪些标志的列表,等等。
发布于 2013-11-13 15:16:29
访问者的意义是很明显的,但稳定的意义则不是。
稳定表示不可变字段(即val)的getter或方法参数,该方法参数在方法的范围内类似不可变。我猜这是用来通过消除重新评估来优化的。
https://stackoverflow.com/questions/18023683
复制相似问题