Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added general note

...

Note however, that the performance gains achieved by doing so may be meeker than the benefits of having more robust code that also takes non-constant and non-interned values. Moreover, such behavior encourages ambiguity that hinders selection of proper methods for comparing String objects.

Wiki Markup
In general, for any two objects, it is permissible to compare their elements provided that the class is a singleton. The use of static factory methods over constructors facilitates instance control which in turn limits the effective number of instances of an immutable class to one. Thus, for two objects a and b, a.equals(b) is true only when a==b \[[Bloch 08|AA. Java References#Bloch 08]\]. The {{String}} class does not possess these characteristics.

Risk Assessment

Using the equality or relational operators to compare objects may lead to unexpected results.

...