Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > equals and hashCode

Reply
Thread Tools

equals and hashCode

 
 
Gregory A. Swarthout
Guest
Posts: n/a
 
      12-19-2003
From Object's JavDoc:

> If two objects are equal according to the equals(Object)
> method, then calling the hashCode method on each of
> the two objects must produce the same integer result.


It doesn't say why this must be. Does anyone know?
 
Reply With Quote
 
 
 
 
Wendy S
Guest
Posts: n/a
 
      12-19-2003
"Gregory A. Swarthout" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> > If two objects are equal according to the equals(Object)
> > method, then calling the hashCode method on each of
> > the two objects must produce the same integer result.

>
> It doesn't say why this must be. Does anyone know?


Yes, but I can't explain it nearly as well as Chapter 3 of Effective Java:
http://java.sun.com/docs/books/effective/chapters.html

--
Wendy


 
Reply With Quote
 
 
 
 
Silvio Bierman
Guest
Posts: n/a
 
      12-20-2003

"Gregory A. Swarthout" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> From Object's JavDoc:
>
> > If two objects are equal according to the equals(Object)
> > method, then calling the hashCode method on each of
> > the two objects must produce the same integer result.

>
> It doesn't say why this must be. Does anyone know?


Look at what Wendy wrote. Without this requirement using hashing in general
container classes (HashMap, HashSet) would not be feasible.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
override equals and hashcode lowenbrau Java 9 08-10-2007 03:28 AM
Be Honest: Do you implement hashCode(), equals(), and toString() for every class you write? Danno Java 29 09-15-2006 11:00 PM
equals() and hashcode() not working... e.chaitanya@gmail.com Java 6 04-11-2006 04:55 PM
equals and hashCode Tom Dyess Java 28 06-23-2005 05:29 PM
Infinite loops in hashCode() and equals() Mike Schilling Java 11 06-12-2004 04:46 AM



Advertisments