Comparing references in Java
The default bahaviour of equals() is to compare the two objects using the == operator. So if you want the default bahaviour use ==, if you want your overridden behaviour use equals().
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.
That's what the == operator does.