3 ms·
Kotlin data classes cannot be extended and they can only extend sealed classes. So they are effectively sealed already.
by jillesvangurp 7y ago
Kotlin data classes cannot be extended and they can only extend sealed classes. So they are effectively sealed already.
- dwohnitmok 7y agoI perhaps should have been more explicit about the goal rather than the method, since sealing records is only one part of this. This is all in service of private constructors. You effectively cannot have private constructors for data classes in Kotlin because the copy method remains public and cannot be "turned off." `sealed abstract case class` in Scala gets rid of that. Private constructors for record types is a fantastic light-weight way of incorporating runtime checks into compile-time types.