Java is the future !: What's the difference between “.equals and ==” ?

Monday, October 18, 2010

What's the difference between “.equals and ==” ?

In Java, == always just compares two references (for non-primitives, that is) - i.e. it tests whether the two operands refer to the same object.

However, the equals method can be overridden - so two distinct objects can still be equal.

For example:

No comments:

Post a Comment