...
EXP01-EX0: Using reference equality in place of object equality is permitted only when the defining classes guarantee the existence of, at most, one object instance for each possible object value. This generally requires that instances of such classes are immutable. The use of static factory methods, rather than public constructors, facilitates instance control, which is a key enabling technique.
Objects that are instances of classes that provide this guarantee obey the invariant that for any two references {{ Wiki Markup a
}} and {{b
}}, {{a.equals(b)
}} is exactly equivalent to {{a
==
b
}} \ [[Bloch 2008|AA. References#Bloch 08]\]. The {{String
}} class fails to meet these requirements and consequently fails to preserve this invariant.
EXP01-EX1: Use reference equality to determine whether two references point to the same object.
...
CWE ID 595, "Comparison of Object References Instead of Object Contents" | |
| CWE ID 597, "Use of Wrong Operator in String Comparison" |
The Elements of Java Style | Rule 79: Use |
Bibliography
...
[[FindBugs 2008AA. References#FindBugs 08]] | ES: Comparison of String objects using == or != | ]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="34ad4809-ea07-41ad-9c99-472dde2b4ca2"><ac:plain-text-body><![CDATA[ |
[[JLS 2005AA. References#JLS 05]] | http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5] | ]]></ac:plain-text-body></ac:structured-macro> | |
|
...