我在构造函数上使用 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?
}
}
我想知道我是否缺少任何东西。任何不需要复制参数默认值的想法?
谢谢!