Data Class Inheritance could lead to problems


Data class inheritance is on the roadmap for Kotlin 1.1, but I wonder whether it is a good idea to introduce it. As far as I know a data class should be able to inherit from an arbitrary class. This example points out the problems inheritance would introduce. In short equals would no longer be symmetric.

This topic has been discussed in the Scala community.


Not “an arbitrary class”

Data classes are good, but we did not support any inheritance for those.
1.1 will fix that; you will be able to say, have a sealed class, and be able to extend a data class from it.


@medium: Data classes remain final, so there will be no situation as discussed on stackoverflow when you inherit one case class from another case class.

@fvasco: No there will be no limitation that data classes can only inherit sealed classes.


Can you explain or submit a reference?


There is no point in limiting data class inheritance to sealed classes, as it can be easily worked around by inheriting sealed class from whatever and then inheriting data class from that sealed class.


For future reference: