...
As a general rule, use the Object.equals()
method to check whether two objects are abstractly equal to each other. Reserve Programs must reserve use of the equality operators ==
and !=
for testing whether two references specifically refer to the same object. (This ; this is reference equality. ) Also see rule "MET09-J. Classes that define an equals() method must also define a hashCode() method."
...
- The cost of
String.intern()
grows as the number of intern strings grows. Performance should be no worse than n log n, but the Java Language Specification makes no lacks a specific performance guarantee. - Strings that have been interned become immortal: they cannot be garbage collected. This can be problematic when large numbers of strings are interned.
...
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; this is a key enabling technique.
Wiki Markup |
---|
Objects that are instances of classes that provide this guarantee obey the invariant that, for any two references {{a}} and {{b}}, {{a.equals(b)}} is exactly equivalent to {{a == b}} \[java:[Bloch 2008|AA. Bibliography#Bloch 08]\]. The {{String}} class doesfails notto meet these requirements and, consequently, doesfails notto obeypreserve this invariant. |
EXP01-EX1: Use reference equality to determine whether two references point to the same object.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="37c7bc256945c9d9-33a33052-4c344cea-88e7b936-e8a8cdd24d9a0bc063827a82"><ac:plain-text-body><![CDATA[ | [java:[FindBugs 2008 | AA. Bibliography#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="678dae5427532b01-5226865e-45cd4b33-85feafd6-aa3bffb876b8bbe18961b26c"><ac:plain-text-body><![CDATA[ | [java:[JLS 2005 | AA. Bibliography#JLS 05]] | [§3.10.5, "String Literals" | http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5] | ]]></ac:plain-text-body></ac:structured-macro> |
|
...