📎 Webclip
The Codeless Code: Case 15 Immutable
A novice from the Temple of Three Stones asks why Java Strings are immutable, since converting a field to mixed case seems to require extra objects and copied characters. A sister answers with a comparison between a brass coin and an egg, and he takes the lesson to heart.
He then makes all his classes immutable, so every change requires a new instance. The result is that his constructors become very large and complex, and the Java master assigns the nun to correct him.
Reading notes#
- The novice is new to Java and is bothered by the cost of changing a String.
- The sister explains immutability through the contrast between something that can be exchanged again and something that cannot.
- He applies immutability to all classes, not only Strings.
- This choice makes constructors large and complex.
- The master responds by having the nun correct the novice.
