我正在使用Scala 2.8默认参数构造函数,由于Java兼容性的原因,我想要一个使用默认参数的无参构造函数。
出于非常明智的原因,这不起作用:
出于非常明智的原因,这不起作用:
class MyClass(field1: String = "foo", field2: String = "bar") {
def this() = {
this() // <-- Does not compile, but how do I not duplicate the defaults?
}
}
我在想我是否遗漏了什么。有没有不需要复制参数默认值的想法?
谢谢!