File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interdependence of equals() and hashCode() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interdependence of equals() and hashCode()" Watch "interdependence of equals() and hashCode()" New topic

interdependence of equals() and hashCode()

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
if x.equals(y) is true, then x.hashCode() == y.hashCode()must be true.
If the above statement is true, why is that contract of equals method does not mention this requirement?
Alex Radomski

Joined: Apr 24, 2003
Posts: 24
Hi Barkat,
It does not get mentioned in equals() contract becuase it belongs to hashCode() contract.

I agree. Here's the link:
subject: interdependence of equals() and hashCode()
It's not a secret anymore!