+ 4

What is purpose of override hashCode() in Java?

This method hashCode(), why we need it and what is purpose to override this method and when? Definitely I'm beginner and this stuck in my mind.

17th Jun 2019, 9:44 AM
Felina
Felina - avatar
2 odpowiedzi
+ 8
Whenever it(hashcode) is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified
17th Jun 2019, 1:56 PM
Prabhat
Prabhat - avatar
+ 5
Hope this code helps you: https://code.sololearn.com/cK2H7CdVEq45/?ref=app In the comments you will also find resources about each methods.
17th Jun 2019, 11:21 PM
Denise Roßberg
Denise Roßberg - avatar