+ 1

HashCode() and equals()

Whats the sense of both? Why do i need a hashcode methode if i overwrite equals? isnt it kinda the same?

7th Dec 2020, 8:23 PM
Manfred h
1 ответ
+ 5
Although they may produce the same or similar results in some cases, they are not the same. They do however have a tight bond and are relational. The hashCode() method represents the identity of the current instance of an object, while the equals() method typically represents the equality between 2 object instances where the hashCode may be used for comparison. Here's some more info: https://www.baeldung.com/java-equals-hashcode-contracts https://www.journaldev.com/21095/java-equals-hashcode https://www.google.com/amp/s/www.geeksforgeeks.org/equals-hashcode-methods-java/amp/
8th Dec 2020, 12:00 AM
ChaoticDawg
ChaoticDawg - avatar