如果我实例化和Base2运行良好为什么下面的Scala代码会抛出NullPointerException?
class Base2 {
class Benchmark {
def onTrade() {
println("base onTrade")
}
}
protected val benchmark = new Benchmark
benchmark.onTrade
}
class Base3 extends Base2 {
override val benchmark = new Benchmark {
override def onTrade() {
println("sub onTrade")
}
}
}
// to run
new Base3
异常信息:(!不和Base2)
java.lang.NullPointerException
at Base2.<init>(<console>:16)
at Base3.<init>(<console>:19)
at .<init>(<console>:10)
at .<clinit>(<console>)
at .<init>(<console>:11)
...
请勿重写混凝土瓦尔。这就是疯狂(或者更重要的是,非工作软件)。 –