Immutable object

From CSSEMediaWiki
Revision as of 06:21, 5 October 2008 by Jason Clutterbuck (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

An immutable object is one in which the value or state can not be changed.

The value is set when the object is created. If the value of the object needs to be changed then the object is replaced by an object containing the new value. The string object in Java is an example of an immutable object. Any string operations in Java return a new object containing the result of the operation. Using immutable objects removes synchronisation problems that can occur in multi threaded programmes. It also removes worries on some level about side effects.

Personal tools