The contract for Set.equals()
is that every member of each set is contained in the other. Each contains
test relies on the equals()
method of the objects in the sets.
This specification requires that no Set
implementation can rely on the default implementation of equals()
, which is object identity. (As far as the Set
specification goes, the objects in the set are free to use the default Object.equals()
to test equality. But if you have a set of sets, the objects in the (outer) set are themselves Set
objects, and thus subject to the same Set
contract regarding equals()
.)
For more info, see the docs for Set.equals()
and Set.contains(Object)
.