| Author |
what is hashcode and equals contract?
|
varinder mahajan
Ranch Hand
Joined: Jun 11, 2008
Posts: 47
|
|
|
what is hashcode and equals contract?
|
Beat the world,if you can.......
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
This is described in the API, under java.lang.Object's hashCode() method.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Mario Razec
Greenhorn
Joined: Aug 01, 2008
Posts: 17
|
|
hi... I understand that: equals() using to comparison, refers to equivalence relations. hashCode() is id number allocated to an object by JVM. Contract: When you use equals() and hashCode() methods is necessary to override these methods But checking please: http://www.coderanch.com/t/269570/java-programmer-SCJP/certification/Let-discuss-hashcode-contract http://www.javaworld.com/community/?q=node/1006 http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf
|
 |
arulk pillai
Author
Ranch Hand
Joined: May 31, 2007
Posts: 3185
|
|
The key thing to remember is that: -- If two objects are equal then they should have the same hascode but the reverse is not true (i.e. If two objects have the same hashcode does not mean that they are equal) -- You need to use the same attributes in your equals & hashCode methods Look at the doco for further info.
|
Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
|
 |
Sandeep Bhandari
Ranch Hand
Joined: Apr 16, 2004
Posts: 201
|
|
|
Besides checking about the implications of equals and hashcode values, the exam may simply ask that if you implement equals() method, which other method you should implement?
|
SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: what is hashcode and equals contract?
|
|
|