What You Lose
You cannot create subclasses of data classes. A data
class cannot be marked with open
to allow it to be extended.
If subclasses were allowed, it is possible that subclasses would change the class definition in ways that might make the code-generated equals()
and other methods be invalid. Hence, at least right now, Kotlin prohibits subclasses of data classes.
A side-effect of the no-subclasses limitation is that data classes cannot be abstract.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.