Oops!  Yes, James and Ernest are correct... an error of omission on my part.
You do indeed need to override the hashCode() method, too.

I was fortunate enough to win a copy of Thinking in Java 3rd ed by Bruce
Eckles at my local Java users group.  It is available *free* as an
electronic book at http://mindview.net/Books/DownloadSites .  If you look at
Chapter 11: Hashing and Hash Codes you will find the complete example that
James mentioned.  Just remember that, by default, equals() only compares
object references -- for anything else you have to write a custom
implementation.

Cheers,

-JM
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, August 03, 2004 12:42 PM
> To: [EMAIL PROTECTED]
> Subject: Re: JESS: new to jess
>
>
> I think James Owen wrote:
> > One other thing, something that most "old timers" even forget.  :-)  If
> > you re-write equals for a class that already exists or one that you
> > inherit then you have to re-write the hash map table.
>
> Of course what jco means is that if you override equals(), you should
> override hashCode() as well; the details of doing this correctly are
> spelled out quite clearly in the Javadocs for the Object class. Joshua
> Bloch's book is, indeed, good as well.
>
>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Advanced Software Research          Phone: (925) 294-2154
> Sandia National Labs                FAX:   (925) 294-2234
> PO Box 969, MS 9012                 [EMAIL PROTECTED]
> Livermore, CA 94550         http://herzberg.ca.sandia.gov
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
>

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to