posted 13 years ago
Hi,
When i try to run the below program with out the hashCode() but equals(), I am getting output as null.
But i tried to run with hashCode() and equals() method, I am getting the proper value(means in this case Feb).
I know equals() method will do object comparision( in this case by using name). But using equals() alone why I am not getting the proper value.
I analysed the below one like this. If we were not implemented hashCode(), default hashCode() method will call and store all objects in one single bucket in that it invokes equals method to find correct object.
After reading all the things from K&B, I got confused over all. Can any one explain this briefly?(when to implement equals() and when to implement hashCode())