A data class cannot extend another data class but ...
# android
s
A data class cannot extend another data class but it can extend a normal open class. I was expecting this wouldn't work. 🤨 Why not allow data class to extend another data class? What am I missing?
z
The copy function on the parent data class, for one, wouldn’t know how to copy the subclass.
e
that might be solvable with overriding, but allowing data class inheritance will cause the equals method to be non-reflexive. I don't think there's a great way to handle that in general
👍 1
z
there’s a lot of things about data classes that could be done in ways that would make them much more flexible with other features of the language. I think another reason is that you probably couldn’t rely on as many of the guarantees of a data class if it could have subclasses, since subclasses could break those contracts
👍 1
s
It could be solved by forcing to override the copy method and the equals method in the subclass... easy I think. 🙂 Anyway I'll keep the open class for now.