What I'm asking is what the == operator uses for the String class in Java? What is the excuse that he does not overload him, so that he makes a deep comparison?
== and equals have a completely different application. == confirms whether reference equality exists Equals confirms whether objects are the same.
An example of reference equality is IdentityHashMap. There may be a case when only an object inserting something into the IdentityHashMap has the right to receive / delete the object.
overloading reference equality can lead to undesirable complexity for java. for example if (string) {do deep equality} else {make referential equality}
/ ***************************************.... **************** /
Public class IdentityHashMap extends AbstractMap implements Map, Serializable, Cloneable
This class implements a Map interface with a hash table, using referential equality instead of equality of objects when comparing keys (and values). In other words, in IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1 == k2). (In normal map implementations (for example, HashMap), two keys k1 and k2 are considered equal if and only if (k1 == null? K2 == null: k1.equals (k2)).)
This class is not a general purpose map implementation! Although this class implements the Map interface, it intentionally violates the general Map contract, which provides for the use of the equals method when comparing objects. This class is intended for use only in rare cases when the semantics of referential equality is required.
source share