我在系统中有一条旧信息,我希望能够将其映射到系统中的新版本信息。
为什么不能重载我的案例类?
为什么不能重载我的案例类?
case class Message(a:Int, b:Int)
case class NewMessage(a:Int, b:Int, c:Int) {
def this(msg : Message) = this(a = msg.a, b = msg.b, c = 0)
}
val msg = Message(1,2)
val converted = NewMessage(msg)
这段代码似乎无法编译。:(
new
运算符即可编译代码。 - Tomasz Nurkiewicz