我正在尝试按照这篇文章中所述的方式创建案例类。
sealed abstract case class Exp()
case class Literal(x:Int) extends Exp
case class Add(a:Exp, b:Exp) extends Exp
case class Sub(a:Exp,b:Exp) extends Exp
然而,在IntelliJ中我遇到了以下错误。我理解为什么这是被禁止的(为什么Scala中不允许case-to-case继承)。在这里有什么替代方法吗?
Error:(2, 13) case class Literal has case ancestor A$A34.A$A34.Exp, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.
case class Literal(x:Int) extends Exp
^