Extend data class in Kotlin

The truth is: data classes do not play too well with inheritance. We are considering prohibiting or severely restricting inheritance of data classes. For example, it’s known that there’s no way to implement equals() correctly in a hierarchy on non-abstract classes.

So, all I can offer: don’t use inheritance with data classes.

Leave a Comment