| Author |
hash codes for classes that do not implement the hashCode() method
|
Rachel Glenn
Ranch Hand
Joined: Oct 24, 2012
Posts: 95
|
|
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
Joined: Apr 06, 2010
Posts: 3795
|
|
|
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.
|
 |
 |
|
|
subject: hash codes for classes that do not implement the hashCode() method
|
|
|