• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashcode()...

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some questions he has given code for equals method for which he is asking us to select most appropiate hashcode method from given choices?

how can we answer these types of questions?

can anyone explain with simple example?
 
anand-k jha
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please look below example:



Hashcode always will return a fixed value for an object, so
Second method is not appropriate here.
I think this will help you.

Anand.
 
Djonatah Stiegler
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should choose the hashCode() method that uses the same variables used on the equals() method.

Bye
<><
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic