Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

hash code equal method  RSS feed

 
jacob deiter
Ranch Hand
Posts: 587
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is common understanding that if Equal method of a Java class overridden then Hash code method should be overridden

1) any one explain why it so?

2) What happen if overridden one method (Ex:hash code) and not overridden the second method?

3) what is the real use of hash code in java?.Is it have any importance in hash map?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article does a good job of explaining equals() and hashCode().
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at equals() and hashCode()
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:2) What happen if overridden one method (Ex:hash code) and not overridden the second method?

3) what is the real use of hash code in java?.Is it have any importance in hash map?
Have you tried it?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!