Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Entry interface defines methods like equals and hashCode?

I saw that interface java.util.Map.Entry has methods:

boolean equals(Object o);
int hashCode();

Why are above methods a part of Entry interface when same methods are inherited from the Object class?

Thanks and Regards, Rahul

like image 632
rbhawsar Avatar asked May 15 '26 03:05

rbhawsar


1 Answers

As the overriding defintion says; It is used when a class that extends from another class wants to use most of the feature of the parent class and wants to implement specific functionality in certain cases. And the oracle documentation for boolean equals() says;

This ensures that the equals method works properly across different implementations of the Map.Entry interface.

So for the specific implementation of equals() method the boolean equals(Object o) and int hashCode() are overridden.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!