4 ms·
While '==' meaning compares equal by value would be nice; it makes the == operator quite complex. If it's a general comparison operator, it would need to recurs
by toast0 9y ago
While '==' meaning compares equal by value would be nice; it makes the == operator quite complex. If it's a general comparison operator, it would need to recursively compare all the members, and avoid looping on circular references, or risk == running forever.
Certainly, one can come up with examples of how a different operator == would be useful for certain types of objects (including Integer), but the architects of Java strongly felt that an operator should always behave the same, regardless of the type of its operands, unless the operator is + and the objects are Strings.