As Ralph explained,
foo.equals(bar) isn't necessarily always
false if
foo and
bar are two different objects (note that in that case,
foo == bar would indeed always be
false - maybe you're confusing the meaning of
equals() and
==).
However, there is something strange with that
if-statement.
The contract for the
equals() and
hashCode() methods says that if
equals() returns
true, then the hash codes of the two objects must be the same. (You can find more information on this in the API documentation of the
equals() and
hashCode() methods in class java.lang.Object).
Because of that, the second part of the expression in that
if-statement is not necessary, because it would always be
true if the first part of the expression is
true; just this will be exactly the same:
(Unless there is a bug in the implementation of the
equals() or
hashCode() methods of the class of
foo and
bar).
(*edit* Argh, Wouter beat me!
)