Many thanks to Tristan Morris for creating a beautiful illustrated hardcover print edition of the site

tcc-case-title
extremely geeky  extremely geeky

Case 15

Immutable

(Sorry, this page has not yet been translated into the requested language.)

A novice was recently arrived from the Temple of Three Stones where only C was used. He was new to the ways of Java, and soon stumbled upon the immutability of Strings.

“I wish only to convert the contents of this field to mixed case!” he cried. “Yet this requires the construction of a StringBuffer and a new String subsequently, with many untouched characters copied twice between them! For what purpose were Strings designed thus?”

A learned sister heard, and advised him: “The brass coin passed from hand to hand may still be exchanged on the morrow; not so the egg.” The novice was enlightened.

Soon the novice was defining all his classes to be immutable. Not one property could be modified: a new instance had to be created with the necessary changes. His constructors were sometimes astonishingly large and complex.

The Java master was told of this, and said: “Let the form of an egg be cast in brass, and given to the nun to breakfast upon.”

In this manner was the nun charged with correcting the novice.

Topics...  immutability