Specifically, in the case of object reference equality, what does the == operator do?
Does the comparison return true if the references evaluate to the same object a
The ==
operator compares object references to see if they are identical, i.e. they refer to the same object in memory.
The equals()
method compares object references to see if they are equivalent, though not necessarily identical. The default implementation of equals()
uses the ==
operator, but it often makes sense to override this behavior. For example, you might want two BankAccount references to be considered equivalent if they have the same account number, even if they are completely different objects.