3 ms·
Nothing in OOP requires mutable state. Thing changedThing = oldThing.change(); When you start writing code like this, Java can be quite pleasant.
by stickfigure 9y ago
Nothing in OOP requires mutable state.
Thing changedThing = oldThing.change();
When you start writing code like this, Java can be quite pleasant.
- jdmichal 9y agoIt's only very special circumstances where my POD types do not consist entirely of `final` fields. Though I usually skip defensive copying within PODs... One should know better than to trust values from random places. So I defensively copy at use time instead if I want to modify it.
- eropple 9y agoKotlin, Java's superior offspring, is even better, as the use of data classes provides an automatic implementation of a `copy` command. (Scala does too, but Scala also explodes when I look at it, so, enh.)