Skip to Main Content

Java Programming

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!

Difference between equals() method and == operator

807605Oct 12 2007 — edited Oct 12 2007
Hi All,

This is a serious issue am facing... I need some good answers for this.

I know the difference between == operator (which compares references) and equals() method (which compares the instance values).

But, surprisingly I found in the source code of our Object class in the equals() methods implementation that its also using the same == operator to compare. Am pasting the exact implementation.

public boolean equals(Object obj) {
return (this == obj);
}

So what is the difference? Its again comparing references instead of values.

Suggestions will be highly appreciated.

Regards
Naveen
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2007
Added on Oct 12 2007
12 comments
817 views