Inspectopedia
 
2024.3

'Comparable' implemented but 'equals()' not overridden

Warning
New
Last modified: 03 December 2024

Reports classes that implement java.lang.Comparable but do not override equals().

If equals() is not overridden, the equals() implementation is not consistent with the compareTo() implementation. If an object of such a class is added to a collection such as java.util.SortedSet, this collection will violate the contract of java.util.Set, which is defined in terms of equals().

Example:

After the quick fix is applied: