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!
{{short description|Object whose state cannot be modified after it is created}} {{Redirect2|Immutable|Immutability|the Christian doctrine|Immutability (theology)|the album|Immutable (album)|the crypto gaming company|Immutable Pty Ltd}} In [[object-oriented computer programming|object-oriented]] (OO) and [[Functional programming|functional]] programming, an '''immutable object''' (unchangeable<ref>{{cite web|url=http://www.oxfordlearnersdictionaries.com/definition/english/immutable|title=immutable adjective - Definition, pictures, pronunciation and usage notes - Oxford Advanced Learner's Dictionary at OxfordLearnersDictionaries.com|website=www.oxfordlearnersdictionaries.com}}</ref> object) is an [[object (computer science)|object]] whose [[State (computer science)|state]] cannot be modified after it is created.<ref name=Goetz>Goetz et al. ''Java Concurrency in Practice''. Addison Wesley Professional, 2006, Section 3.4. Immutability</ref> This is in contrast to a '''mutable object''' (changeable object), which can be modified after it is created.<ref>{{cite web|url=https://web.mit.edu/6.005/www/fa16/classes/09-immutability/|title=6.005 β Software Construction}}</ref> In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses <!-- YES, THIS IS SPELLED CORRECTLY. IT'S *NOT* "memo*r*ization". READ THE LINKED ARTICLE. -->{{Not a typo|[[memoization]]}} to cache the results of expensive computations could still be considered an immutable object. Strings and other concrete objects are typically expressed as immutable objects to improve readability and runtime efficiency in object-oriented programming. Immutable objects are also useful because they are inherently [[Thread safety|thread-safe]].<ref name=Goetz /> Other benefits are that they are simpler to understand and reason about and offer higher security than mutable objects.<ref name=Goetz />
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)