• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hash codes for classes that do not implement the hashCode() method

 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have a class called Dog, as follows:




This class does not implement the hashCode() method.

Is it guaranteed then that all instances of Dog will produce unique hash codes (that I assume are generated by the java run time) ?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no guarantee they'll be unique. Thing about this: you can create more objects than there are int values, in which case you'd have to have duplicate hash codes. But there's a good chance that they will be distinct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic