Re:Java's records, Lombok's data, and Kotlin's data classes
by snuxoll on Friday May 07, 2021 @09:55PM
(#27082930)
The copy methods that Kotlin generates construct a new instance of the class with the updated fields - so any validation done in the constructor would in fact be done again.
[ Parent
| on HN ]
Re:Java's records, Lombok's data, and Kotlin's data classes
by valenterry on Friday May 07, 2021 @10:34PM
(#27083199)
Yes, that's correct. But instead of catching the error at that point, you would probably rather want to disable these methods from the beginning so that someone cannot even make the mistake of using them and has to go through some custom defined method instead.