Data Class Inheritance could lead to problems


#1

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.


#2

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.


#3

@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.


#4

Can you explain or submit a reference?


#5

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.


#6

For future reference: https://github.com/Kotlin/KEEP/issues/31