For now, you can't inherit another class when defining a data class. To avoid delaying the 1.0 release, the makers of Kotlin have decided to use this restriction to avoid problems that would be caused by this. Imagine a data class, Derived, inherits from a data class, Base; if this happens, then the following questions need to be answered:
- Should an instance of Base be equal to an instance of Derived if they have the same values for all the shared fields?
- What if I copy an instance of Derived through a reference of the type Base?
I am certain that, in the future, all the limitations will be addressed and we will be able to write code similar to this (the Scala developer will be familiar with the construct of Either):
sealed abstract class Either<out L, out R> { data class Left<out L, out R>(val value: L) : Either<L, R>() class Right<...