Handling of equality in Java is usually considered to be one of the
worst design mistakes of the language. The problems are manifold. Firstly,
the
equals method is defined on the
java.lang.Object
type from which all Java classes are forced to inherit. This means that
equality
must be defined for all types,
even those that do not have sensible equality relations
. If an object forgets to override
equals,
then the object is given reference equality by default.
Secondly, the argument to the
equals method is of type
java.lang.Object, meaning that it's
perfectly possible to query the equality of values of different types
(which almost never makes logical sense). Thirdly, the
equals method must be consistent
with the associated
hashCode
method in order for the standard library collections to behave correctly.