我在构造函数上使用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?
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何我想念的东西.任何不需要重复参数默认值的想法?
谢谢!