Troubleshooting

Two Equivalent Objects Are Not Equal

An equality comparison between two object references using == fails even though the objects are equivalent.

When used with reference types, the == operator returns true only if the two references point to the same object. To test for object equivalence, you must use the equals method as declared in the associated class instead of == . If equals has not already been overridden for the class, you must implement an override that returns true if two instances of the class are equivalent relative to the needs of your program. For example, equals is overridden for String to return true if two String objects hold the same sequence of characters.

Mismatched if and else Statements

The ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.