| Author |
Equals and HashCode
|
Juan Manuel Alberto de los Santos
Ranch Hand
Joined: Jun 26, 2008
Posts: 48
|
|
i was reading the K&B book, when i came to this  this code i made, says the contrary thanks ! [ October 10, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
|
 |
Varun Chopra
Ranch Hand
Joined: Jul 10, 2008
Posts: 204
|
|
|
Your book must also say whenever you override equals(), you have to override hashcode() as well.
|
-Varun -
(My Blog) - Mock Tests
|
 |
Thomas Thevis
Ranch Hand
Joined: Sep 02, 2008
Posts: 87
|
|
this code i made, says the contrary
Well, you can always create code breaking so called general contracts. The book specifies the conditions which have to be fulfilled to satisfy the general contract for java.lang.Object.hashCode() (have a look at the javadocs there). It is necessary to satisfy the general contract to ensure that other classes relying on that contract work properly. For example, hash based collections like java.util.HashSet may not work properly if you break that contract. Do you know why? Regards, Thomas
|
SCJP 5.0, SCJD in progress
|
 |
 |
|
|
subject: Equals and HashCode
|
|
|