3 ms·
Here's a tip: instead of changing your objects, you can create a new object with the same values except the ones you want to change. Another option is to use b
by vetler 12y ago
Here's a tip: instead of changing your objects, you can create a new object with the same values except the ones you want to change.
Another option is to use builders (that are mutable), to build/copy your immutable business (?) objects.
- mercurial 12y agoThat's what we do at work. Then when work is done, I look at OCaml and repeat the mantra "I'm not going to think about how many lines it takes in Java to do a functional update 'let foo2 = { foo1 with foo_field = "bar" }'". It is possible to have immutable objects in Java and have the equivalent of functional updates, but it's a hell of a lot of pointless boilerplate. It still beats traditional Java beans, though.