File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes purpose of hash code 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 » Java » Java in General
Bookmark "purpose of hash code" Watch "purpose of hash code" New topic
Author

purpose of hash code

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

Hi,
Can someone plz tell what role hash code plays in object comparison? I am talking abt hashCode method of Object class.


Groovy
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
This page might shed a bit of light on the subject.
http://java.sun.com/docs/books/tutorial/java/javaOO/objectclass.html
Sean
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
In brief, the contract for equals(Object) and hashCode() requires that if a.equals(b), then a.hashCode() and b.hashCode() return the same value.
It is necessary to comply with this contract, even if not using the "hash" containers, because any class is allowed to rely on the contract. For example, suppose class Slow has an equals and hashCode method that are very slow. The contract for equals and hashCode() permits you to do something like this as an optimization:
 
wood burning stoves
 
subject: purpose of hash code
 
Similar Threads
doubt regarding hashcode
collections
hashCode() from Object
Hash Code Implementation
equal() method of class Object