Home > DeveloperSection > Forums > When and why Hashcode override in costume classes?
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    March-28-2015 2:12 AM

 Java Java 
Ratings:


 2 Reply(s)
 646  View(s)
Rate this:
Why we override Hashcode in our costume classes?


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    March-28-2015 2:16 AM

if u want to check object's content then you have to override equal() and hashcode(). basically hashcode() is check reference address only

Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    March-28-2015 2:18 AM

generally for every object contains one unique hashcode generated by jvm. 
hashcode tells the programmer which class object it is. 

OBJECT class produces one unique code for object. i.e, hexa decimal integer. 

if u dont like this hexa decimal numerical value there is a chance to overridde hashcode value and whatever value give for that object then u should override hashCode() method in ur class and return it.

Don't want to miss updates? Please click the below button!

Follow MindStick