The equals method

The documentation of Set says, sets contain no pair of elements e1 and e2 so that e1.equals(e2). The equals() method returns true if the e1 and e2 are in some way equal. It may be different from two objects being identical. There can be two distinct objects that are equal. For example, we could have a color implementation that has the name of the colors as an attribute and two color objects may return true, calling the equals() method on one of them and passing the argument as the other when the two strings are equal. The default implementation of the equals() method is in the code of the Object class and this returns true if, and only if, e1 and e2 are exactly the same and single object.

It seems to be obvious, but my experience ...

Get Java Projects - Second 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.