tunaranch tunaranch -5 years ago 153
Java Question

Comparing references in Java

Let's say that you have overridden an object's equals() and hashCode() methods, so that they use the object's fields.

How you do you check if two references are to the same object, ala the stock equals() method?

Answer Source

Use == on objects to perform identity comparison.

That is what the default implementation of equals() does, but one normally overrides equals() to serve as an "equivalent content" check.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download