• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The purpose of hashCode()

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will it be o.k. to return the unique key on the object as it's hashCode. For example, SSN for Person class and VIN for Vehicle class.
As purpose of hashCode is to evenly distribute objects in collection, this will put one object in each bucket...
Thanks
Barkat
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hashCode has to return an int. Returning a unique int for each unique object is generally best.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic