Usage
Strings and other concrete objects are typically expressed as immutable objects to improve readability and runtime efficiency in object-oriented programming. In Python, Java and the .NET Framework, strings are immutable objects. Both Java and the .NET Framework have mutable versions of string. In Java these are StringBuffer
and StringBuilder
(mutable versions of Java String
) and in .NET this is StringBuilder
(mutable version of .Net String
). Python 3 has a mutable string (bytes) variant, named bytearray
.
Additionally, all of the primitive wrapper classes in Java are immutable.
Enforcement of the pattern can be checked by using specialized compilers (see for example http://pec.dev.java.net/), and there is a proposal to add immutable types to Java.
Similar patterns are the Immutable Interface and Immutable Wrapper.
In pure functional programming languages it is not possible to create mutable objects, so all objects are immutable.
Read more about this topic: Immutable Object
Famous quotes containing the word usage:
“Girls who put out are tramps. Girls who dont are ladies. This is, however, a rather archaic usage of the word. Should one of you boys happen upon a girl who doesnt put out, do not jump to the conclusion that you have found a lady. What you have probably found is a lesbian.”
—Fran Lebowitz (b. 1951)
“Pythagoras, Locke, Socratesbut pages
Might be filled up, as vainly as before,
With the sad usage of all sorts of sages,
Who in his life-time, each was deemed a bore!
The loftiest minds outrun their tardy ages.”
—George Gordon Noel Byron (17881824)
“I am using it [the word perceive] here in such a way that to say of an object that it is perceived does not entail saying that it exists in any sense at all. And this is a perfectly correct and familiar usage of the word.”
—A.J. (Alfred Jules)