case class overloading in Scala -


i have legacy message in system, , able map new version message in system.

why can't overload case class?

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) 

this code doesn't seem compile. :(

you must explicitly call constructor using new operator:

val converted = new newmessage(msg) 

it works because defining second constructor in newmessage while ordinary:

newmessage(1, 2, 3) 

is translated to:

newmessage.apply(1, 2, 3) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -