Abimaran Kugathasan wrote:How to find whether the hashCode method is appropriate to the given equals method? Any suggestion??? (I don't mean the contract between them) Thanks in Advanced!
If you don't mean the contract, I'm not sure what you mean. If you want to find whether it is appropriate, drop your object in a HashTable and see if you can ever find it again. Then, drop 100,000 other objects into the same HashTable and see if you can find yours quickly enough.
The way it is explained in the books I studied is " a HashTable is a series of buckets each with zero or more objects." The hashcode determines which bucket you look in to get the object. The equals determines which object you pull out of the bucket. It is appropriate if your implementation of equals and hashcode makes it possible and efficient to find the right bucket and then the right object. If you have 200,000 members in your HashTable all with the same hashcode, then your code has to find the object using only the equals method in one big "bucket" of objects. If the members are spread out over 2000 buckets, your code just has to search through 100 items to find the right one with the equals method.
If you are not putting the object in a Hashed collection, then override hashcode becomes less important.