【发布时间】:2014-03-13 13:06:47
【问题描述】:
是否可以在 Scala 中定义构造函数签名?
abstract class A {
def this (s: String): this.type // doesn't work
def this (i: Int): this.type // doesn't work
def this (d: Double): this.type // doesn't work
}
class B(var s: String) extends A {
def this(i: Int) = {
this("int "+i.toString())
}
def this(d: Double) = {
this("double "+d.toString())
}
}
【问题讨论】:
标签: scala constructor abstract-class abstract