4 ms·
Records are great. If sealed classes become a thing (https://openjdk.java.net/jeps/360 https://openjdk.java.net/jeps/360) I'll be absolutely elated. And it woul
by dwohnitmok 7y ago
Records are great. If sealed classes become a thing (https://openjdk.java.net/jeps/360 https://openjdk.java.net/jeps/360) I'll be absolutely elated. And it would be just the cherry on top if the two could be used together (along with a private constructor). Scala has this, i.e. `sealed abstract case class`, Kotlin does not, i.e. `sealed data class` is not valid.
I am thrilled that algebraic datatypes (effectively the combination of records and sealed classes) are finally entering mainstream consciousness and that statically typed languages all over the place are starting to adopt them.
- jillesvangurp 7y agoKotlin 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.
- pron 7y agoThat's the plan: https://cr.openjdk.java.net/~briangoetz/amber/datum.html https://cr.openjdk.java.net/~briangoetz/amber/datum.html