Re: .equals(o) and Set membership
From: Raymond DeCampo (rdecampo_at_hold-the-spam.twcny.rr.com)
Date: 12/05/03
- Next message: Raymond DeCampo: "Re: Java HTML formatter?"
- Previous message: Raymond DeCampo: "Re: constructor loading it's object from a file"
- In reply to: Murat Tasan: ".equals(o) and Set membership"
- Next in thread: Murat Tasan: "Re: .equals(o) and Set membership"
- Reply: Murat Tasan: "Re: .equals(o) and Set membership"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Dec 2003 02:37:09 GMT
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
- Next message: Raymond DeCampo: "Re: Java HTML formatter?"
- Previous message: Raymond DeCampo: "Re: constructor loading it's object from a file"
- In reply to: Murat Tasan: ".equals(o) and Set membership"
- Next in thread: Murat Tasan: "Re: .equals(o) and Set membership"
- Reply: Murat Tasan: "Re: .equals(o) and Set membership"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|