The
Java wrapper classes are strongly immutable. You can also create weakly immutable classes by not declaring the class final and declaring all the public methods final. In that manner you can add behavior to the immutable class without breaking immutability. There are several things you must keep in mind when creating immutable classes, for example if part of the immutable state is an object reference you must not return that reference in a method but instead clone the object and return a reference to the clone. There was an excellent article here on JavaRanch a year or so ago about immutability, I'll try to locate that link. But as William said the best place to look is at the source code for
String, Float, Integer, etc in the java.lang package.
[ November 29, 2003: Message edited by: Michael Morris ]
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher