Michael Böiers
12/07/2022, 8:57 AMcopy
method in all classes that meet the necessary requirements - not just in data classes.
A good use case for that are database entities. They have a lot of attributes, and if you model the entities as immutable (which I like to do), you really need to define them as data classes just to get the copy method. But since database tables can have cyclical references, you then need to remember to override hashcode, equals and toString to get back to default behavior. Otherwise you will run into stack overflow errors at runtime. That kind of sucks, when all I ever needed was the damn copy method!ephemient
12/07/2022, 9:00 AMequals
, hashCode
, and toString
, but not copy
. however, it seems like it would be a good place to start experimenting with adding copy
to non-data class
typesMichael Böiers
12/07/2022, 9:08 AMMichael Böiers
12/07/2022, 9:42 AMcopyable class Foo(…)
Michael Böiers
12/07/2022, 9:45 AMAdam S
12/07/2022, 10:43 AMMichael Böiers
12/07/2022, 1:34 PMmcpiroman
12/08/2022, 8:25 AM#[derive(Copy, Clone, Hash, PartialEq)]
Michael Böiers
12/08/2022, 10:02 AM