6/2/2023 0 Comments Serializable kotlin data classIf this semantic doesn't apply to the type you want to create, then you shouldn't create a record. That's the core semantic - everything else follows from here. More precisely, data that's (shallowly) immutable and transparently accessible. So by creating a record you're telling the compiler, your colleagues, the whole wide world that this type is about data. are classes that act as transparent carriers for immutable data. Records are transparent carriers for immutable data It doesn't help that the official documentation also takes the boilerplate angle and while JEP 395 better explains the semantics, due to its scope it's naturally vague when it comes to describing the downstream benefits.įirst semantics, then benefits. The boilerplate reduction is obvious and sexy and easy to demonstrate, so it gets a lot of exposure.īut the semantics and their benefits don't. So these are essentially the same features right?īecause for records, boilerplate reduction is not the purpose, it's just a (welcome) consequence of their semantics. Data class Range ( val low : Int, val high : Int )
0 Comments
Leave a Reply. |