The hashcode of two objects can be same value, and to further confirm it, you can use the equals() method. But, for two objects, if the hashcode are different, then you can say, both are unequal. This scenario in used in HashMap, etc
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Please be polite here, and, Rohit, you are mixing == and equals() method. The original post question asked with related to usage of hashCode() and equals() methods. If you follw the contract, then only you can expect the intended behavior.
In HashMaps, it checks the hashCode() of two objects, if both are same, then it go further to check whether the objects are meaning fully equal. If the hashCode() aren't same, it assumes, the objects shouldn't be meaningfully equal.
But, if don't follow the contract, you can't expect the above behavior.
Rohit Ramachandran wrote:Stephan stop posting replies that are not relevant to the question. Thank you.
Stephen posted a link to the hashCode-equals contract which I think is on topic. Also your tone is against the Be Nice rule at javaranch. Stephan your reply could also have been more nice in reminding Harikrishna to read the contract...