Alex Rivera | Logout

How will Object's .equals and .hashCode will work for my classes?

Asked 2010-11-14T18:40:06.000
129

Say I have my own class

public class MyObj { /* ... */ }

It has some attributes and methods. It DOES NOT implement equals, DOES NOT implement hashCode.

Once we call equals and hashCode, what are the default implementations? From Object class? And what are they? How the default equals will work? How the default hashCode will work and what will return? == will just check if they reference to the same object, so it's easy, but what about equals() and hashCode() methods?

Edit
Report

1 Answer

1

Yes, from Object class since your class extends Object implicitly. equals simply returns this == obj. hashCode implementation is native. Just a guess - it returns the pointer to the object.

answered 2010-11-14T18:43:54.203

Your Answer