如果我實例化和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)
...
請勿重寫混凝土瓦爾。這就是瘋狂(或者更重要的是,非工作軟件)。 –