【发布时间】:2011-08-26 19:39:39
【问题描述】:
想象一下这段简单的代码:
class Constructor() {
var string: String = _
def this(s: String) = {this() ; string = s;}
def testMethod() {
println(string)
}
testMethod
}
object Appl {
def main(args: Array[String]): Unit = {
var constructor = new Constructor("calling elvis")
constructor = new Constructor()
}
}
结果是
null
null
我想成为
calling elvis
null
如何做到这一点?对象创建后无法调用 testMethod 方法。
麻子
【问题讨论】:
标签: scala constructor