Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Immutable object
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Weak vs strong immutability === Sometimes, one talks of certain ''fields'' of an object being immutable. This means that there is no way to change those parts of the object state, even though other parts of the object may be changeable (''weakly immutable''). If all fields are immutable, then the object is immutable. If the whole object cannot be extended by another class, the object is called ''strongly immutable''.<ref>{{cite web | url = http://www.javaranch.com/journal/2003/04/immutable.htm | title = Mutable and Immutable Objects: Make sure methods can't be overridden. | author = David O'Meara | date = April 2003 | work = Java Ranch | quote = The preferred way is to make the class final. This is sometimes referred to as "Strong Immutability". It prevents anyone from extending your class and accidentally or deliberately making it mutable. | access-date = 2012-05-14 }}</ref> This might, for example, help to explicitly enforce certain invariants about certain data in the object staying the same through the lifetime of the object. In some languages, this is done with a keyword (e.g. <code>const</code> in [[C++]], <code>final</code> in [[Java (programming language)|Java]]) that designates the field as immutable. Some languages reverse it: in [[OCaml]], fields of an object or record are by default immutable, and must be explicitly marked with <code>mutable</code> to be so.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)