Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why do we need to override Hascode and Equals method?

843789Nov 24 2009 — edited Jan 7 2010
Hi,

== checks if the two references are equal and .equlas will check if the value is same, if we want .equals to take care of both reference and value are correct. why cant I just override equals with an extra check that references are equal(==).

Please someone elaborate on this and also tell me what role hashcode plays in this.

thanks
Anirudh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2010
Added on Nov 24 2009
22 comments
682 views