3

The following code will yield a compile error saying "case-to-case inheritance is prohibited".

case class BaseEvent(eventType: String, payload: Map[String, Any] = Map())
case class ChildEvent(payload: Map[String, Any] = Map()) extends BaseEvent("ChildEventType", payload) 

I understand I can change BaseEvent to a normal class or a trait to get it compile. But I'd still like to understand why Scala doesn't allow case-to-case inheritance.

Wesley Miao
  • 851
  • 5
  • 8
  • Probably issues with matching when you have a childEvent object it would be both a BaseEvent and a ChildEvent. This is a bit ambiguous. – Juru May 26 '15 at 09:18
  • Actually it was there, but got deprecated. Please see some discussion here hinting at the problems it had http://scala-language.1934581.n4.nabble.com/scala-Do-you-use-case-class-inheritance-td2001640.html – Biswanath May 26 '15 at 11:01
  • 3
    Also this previous SO answer seems to point to the issues http://stackoverflow.com/questions/11158929/what-is-so-wrong-with-case-class-inheritance – Biswanath May 26 '15 at 11:07

0 Answers0