sreeharsha Karanam wrote:I would like to know any real time scenario example where hashcodes are equal for two objects but the objects are not equal
It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
sreeharsha Karanam wrote:The case where the objects are unequal using equals method , my understanding is if objects are unequal in that case the hashcodes of the objects must be unequal, consider the below example.
sreeharsha Karanam wrote:now i get it that its not necessary to product distinct integer results if objects are not equal but if it produces it enhances performance, but am curious to know whether we can make such sample code where objects are not equal using equals method but hashcode produces same integer results for the objects.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |