3 ms·
Oops, meant to say "adding a setter violates immutability"
by pigs 15y ago
Oops, meant to say "adding a setter violates immutability"
- masklinn 15y agoBean-type setters, definitely. On the other hand, you could have "setters" using the same naming convention which do a clone-and-replace (and return the new object), that would not violate immutability (and would be easier than building objects from scratch every time from the outside) e.g. Type setFoo(FooType foo) { return new Type( this.field0, this.field1, this.field2, foo, // bam this.field4); } many functional languages have that behavior when manipulating "records".