y
06/10/2025, 6:18 AMdata class
has a feature where you opt-out of automatic generation of equals()
(etc.) by moving a property outside of the primary constructor... this (imo) is a good feature.
but copy()
prohibits a non-public primary constructor for a data class
, so how do you even exclude anything that needs to be set at init? do I really need to fall back to manual implementation any time I have such a property?
you can use a default value for such properties (or even lateinit var
), and initialize them to a non-default value via a secondary constructor. but since the primary constructor is public this seems rather error-prone.y
06/10/2025, 6:38 AMdata class
?loke
06/11/2025, 4:45 AMy
06/11/2025, 5:54 AMloke
06/11/2025, 10:51 AMKlitos Kyriacou
06/11/2025, 12:11 PMcopy
function will also be private.y
06/11/2025, 12:21 PMy
06/11/2025, 12:22 PMcopy
-like function and delegate to the private one.voohbar
06/12/2025, 5:20 PMdata class
doesn't do exactly what you want, just use class
and you will be better off
yes, they could have designed them better, I think they were a bit rushed and are probably very hard to evolve at this pointloke
06/16/2025, 1:34 PM