我想在Scala中繼承一個類。我的父類是如何繼承scala中的類
case class Person (name:String, age:Int, valid:Boolean)
我的子類是
case class MarriedPerson (override val name: String,
override val age: Int,
override val valid: Boolean,
spouse: Person) extends Person(name, age, valid)
當我嘗試,我得到一個錯誤說
: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.
- 爲什麼會出現這種情況,如何我弄在這附近得到一個
case class
繼承另一個case class
? 如果我在父類中刪除了「案件」,我得到一個錯誤說 是
:15: error: value name overrides nothing override val name: String,
爲什麼不能在case class
不是從一個普通的類在這種情況下繼承?
https://stackoverflow.com/questions/12705309/scala-case-class-inheritance –