in the example of equals operator in my sun certified book it was a code like below
but it prints the same output even though if we remove hashCode() method ...so then why they have used it over here
if they have used it that means is should have some specific task to perform
so what is that task ?
Because e1 and e2 are equal, value should be "Hello World". It will be null however, because you haven't overridden hashCode(). As a result, the two equal objects e1 and e2 have different return values for hashCode(), and the Map gets all confused and returns the wrong result.
If you would now uncomment the hashCode() implementation it prints "Hello World" as expected.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: why they use hashCode() method in equals() method