在类构造函数中声明“val”时会发生什么变化?

时间:2015-05-08 12:43:47

标签: scala

使用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

0 个答案:

没有答案