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

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -