In the FAQ on this page its stated -
Quote:
However, item1 and item2 are Java Map instances,
and the equals() implementation of a map is based on the key sets of
the map.
This statement is false cos in JDK5 AbstractMap.java implements equals thus
Code:
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Map))
return false;
Map<K,V> t = (Map<K,V>) o;
if (t.size() != size())
return false;
try {
Iterator<Entry<K,V>> i = entrySet().iterator();
while (i.hasNext()) {
Entry<K,V> e = i.next();
K key = e.getKey();
V value = e.getValue();
if (value == null) {
if (!(t.get(key)==null && t.containsKey(key)))
return false;
} else {
if (!value.equals(t.get(key)))
return false;
}
}
} catch(ClassCastException unused) {
return false;
} catch(NullPointerException unused) {
return false;
}
return true;
}
So this implementation of equals does look at and compare values also(not just keys as stated).
Am i missing something here or not understanding what the author meant ??