On 23/02/2012 02:44, David Holmes wrote:
All of the SynchronizedX.equals methods should be fixed ie
SynchronizedSet, SynchronizedList and SynchronizedMap. It should
always be valid to ask if a.equals(a). The idiomatic form used
elsewhere (CheckedXXX) is:
public boolean equals(Object o) { return o == this || list.equals(o); }
I'm not a fan of collections containing themselves, but I think it is
simple to fix contains(o)/contains[Key]|[Value](o) and remove(o) in a
similar way. Though none of the wrapped collections currently handle
that case, so I'm okay with not addressing this part.
I don't see the recursion potential in hashCode() in the wrappers.
The hashCode of a Set requires summing the hash codes of each of the
elements so it can't work for the case that a set contains itself.
Anyway, I think the best we can do it to have the equals methods use the
above form. I wasn't aware of the warning in List that Sean pointed out
and maybe there should be similar warnings elsewhere.
-Alan