This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hash codes for classes that do not implement the hashCode() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hash codes for classes that do not implement the hashCode() method" Watch "hash codes for classes that do not implement the hashCode() method" New topic
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: 4343
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hash codes for classes that do not implement the hashCode() method
 
Similar Threads
How many objects can you create in JVM with very large RAM.
tricky question about HashMap + equals
What's the difference between hashcode() and equals() methods?
HashMap question
hashcode