Re: .equals(o) and Set membership
From: Murat Tasan (tasan_at_eecs.cwru.edu)
Date: 12/05/03
- Next message: Tim Smith: "mindless: Do you have a good name for a class that...?"
- Previous message: Jess Bring-Larsen: "Re: free C compiler under W2000 platform for JNI"
- In reply to: Raymond DeCampo: "Re: .equals(o) and Set membership"
- Next in thread: hiwa: "Re: .equals(o) and Set membership"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Tim Smith: "mindless: Do you have a good name for a class that...?"
- Previous message: Jess Bring-Larsen: "Re: free C compiler under W2000 platform for JNI"
- In reply to: Raymond DeCampo: "Re: .equals(o) and Set membership"
- Next in thread: hiwa: "Re: .equals(o) and Set membership"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]