On doing a get operation on a hashmap the key objects is taken, its hashcode function is called it's hashcode is compared to the hashcodes of the enetered keys by again calling the hascode function. On a match the key objects equals() function is called and then it is compared to the equals function of the stored key objects on a match again the value object is retrieved. In such a scenario why is it necessary to overide the equals and hashcode methods of the value objects? As the hashcode and equals methods of value object is never called?
please tell me if I am missing something.
Nonetheless over-ridding the equals method is a very normal requirement for most classes even if the class just participates as a 'value' in the hashmap. Of course if you override equals you **must** override hash code!!
Also, the term "value object" should probably be avoided here, as it has two other meanings which have nothing to do with HashMaps. The correct meaning is this one, while the sadly better-known meaning is this one. Note that the second meaning has now been renamed Data Transfer Object, but people still erroneously use the term Value Object here. Anyway, best to avoid the term here as neither meaning seems to be what you mean here.