Wiki Markup |
---|
Immutability helps to supporting security reasoning. It is safe to share immutable objects, without risk that the recipient can modify something that we are relying upon \[[Mettler 2010B|AA. Bibliography#Mettler 2010B]\]. |
Wiki Markup |
---|
Programmers could incorrectly expect that declaring a field or variable {{final}} makes the referenced object immutable. Declaring variables that have a primitive type to be {{final}} does prevent changes to their values after initialization (unless the unsupported {{sun.misc.Unsafe}} class is used). However, when the variable has a reference type, the presence of a {{final}} clause in the declaration only makes _the reference itself_ immutable. The {{final}} clause has no effect on the referenced object. Consequently, the fields of the referenced object can be mutable. For example, according to the _Java Language Specification_ \[[JLS 2005|AA. Bibliography#JLS 05]\], [§4§4.12.4|http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.4], "{{final}} Variables," |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="88664594f1455b5f-3ef45245-48174e60-8ccdafa9-88716efdbeac3bec71c023e1"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 13: Minimize the accessibility of classes and members | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0d8bfcf113eaead7-fe230355-41874157-939fab77-ee2121b5dccc7da6190a7b15"><ac:plain-text-body><![CDATA[ | [[Core Java 2004 | AA. Bibliography#Core Java 04]] | Chapter 6 | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="652259eed6067805-a80dd9bc-461c415c-9972b0d5-43b0bb5d7338115ca2b33852"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§4§4.12.4 "final Variables" | http://java.sun.com/docs/books /jls/third_edition/html/typesValues.html#4.12.4] ]]></ac:plain-text-body></ac:structured-macro> |
| ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5c82720c8808f822-ff2012ad-4a094903-8f57ba36-f97c645c73c48bec9a5f841d"><ac:plain-text-body><![CDATA[ | [[Mettler 2010B | AA. Bibliography#Mettler 2010B]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...
OBJ01OBJ02-J. Declare data members as private and provide accessible wrapper methodsMinimize the accessibility of classes and their members 04. Object Orientation (OBJ) OBJ04-J. Provide mutable classes with copy functionality to allow passing instances to untrusted code safely