0
What is equals() and hashCode() method of a class ?
Explain with example code which depicts real usage of equals() and hashCode() mehod of java.
2 Antworten
+ 1
Both come from Java.lang.Object
equals: returns boolean, proofs for equlity.
hashCode: Returns an int value based on the internals of the object. It is nessaccary for collection stuff. e.g. speed up collection.
read this for further info:
http://www.programcreek.com/2011/07/java-equals-and-hashcode-contract/