Inspectopedia 2025.2 Help

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

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:

class Length implements Comparable<Length> { private int cm = 0; @Override public int compareTo(@NotNull Length o) { if (cm == o.cm) return 0; return cm < o.cm ? -1 : 1; } }

After the quick fix is applied:

class Length implements Comparable<Length> { private int cm = 0; @Override public int compareTo(@NotNull Length o) { if (cm == o.cm) return 0; return cm < o.cm ? -1 : 1; } @Override public boolean equals(Object o) { return o instanceof Length && compareTo((Length) o) == 0; } }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ComparableImplementedButEqualsNotOverridden
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Probable bugs

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection ComparableImplementedButEqualsNotOverridden

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025