Re: .equals(o) and Set membership

From: Murat Tasan (tasan_at_eecs.cwru.edu)
Date: 12/05/03


Date: Fri, 5 Dec 2003 14:08:34 -0500

thanks much, i totally forgot about that!

murat

On Fri, 5 Dec 2003, Raymond DeCampo wrote:

> Murat Tasan wrote:
> >
> > i thought the Set code checks for membership by applying the .equals()
> > method, which at runtime should bind to my overridden method, no?
> >
>
> No, that is not correct. Whenever equals() is overloaded, hashCode()
> must be overloaded as well. The Collections classes depend on
> hashCode() and equals(). Read the javadoc for java.lang.Object
> carefully and implement hashCode() for your classes for which you have
> overridden equals() and you will see better results.
>
> HTH,
> Ray
>
>

-- 
Murat Tasan
mxt6@po.cwru.edu
tasan@eecs.cwru.edu
murat.tasan@cwru.edu
http://genomics.cwru.edu