I am trying to inherit a class in Scala. My Parent class is
case class Person (name:String, age:Int, valid:Boolean)
My child class is
case class MarriedPerson (override val name: String,
override val age: Int,
override val valid: Boolean,
spouse: Person) extends Person(name, age, valid)
When I try this, I get an error saying
:13: error: case class MarriedPerson has case ancestor Person, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.
- Why is this the case and how I get around this to get a
case class
to inherit anothercase class
? If I remove the "case" in the parent class, I get an error saying that
:15: error: value name overrides nothing override val name: String,
Why can't a case class
not inherit from a normal class in this case?