有人能解释一下为什么:
abstract class Super(var title: String)
class Sub(title: String) extends Super(title) {
def test = println(title)
}
val s = new Sub("a")
s.test
s.title = "b"
s.test指纹:
a
a而不是:
a
b发布于 2013-09-07 18:14:26
很简单。您只引用构造函数param,而不是继承的变量。您可以重命名构造函数param,或者使用this.前缀引用var。
class Sub(titleP: String) extends Super(titleP) {
def test = println(title)
}https://stackoverflow.com/questions/18676328
复制相似问题