Home:ALL Converter>How can I copy a case class with its trait?

How can I copy a case class with its trait?

Ask Time:2021-11-23T05:29:47         Author:gav.newalkar

Json Formatter

I have the following:

scala> trait Tail
scala> case class Cat(name: String)
scala> val aa = new Cat(name = "bob")
val aa: Cat with Tail = Cat(ben)
scala> val bb = aa.copy(name = "ted")
val bb: Cat = Cat(ted)

Why is it that bb didn't inherited the Tail trait?

How can I copy aa and still preserve the trait?

Author:gav.newalkar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70072591/how-can-i-copy-a-case-class-with-its-trait
yy