使用val
声明构造函数值时,类中的哪些更改?我注意到它的行为有以下不同:
scala> :paste
// Entering paste mode (ctrl-D to finish)
class Foo(value: String) extends Bar
class Bar { this: Foo =>
def go = println(value)
}
// Exiting paste mode, now interpreting.
<console>:9: error: not found: value value
def go = println(value)
^
scala> :paste
// Entering paste mode (ctrl-D to finish)
class Foo(val value: String) extends Bar
class Bar { this: Foo =>
def go = println(value)
}
// Exiting paste mode, now interpreting.
defined class Foo
defined class Bar