rspec/rules/S1210/description.adoc
2020-12-23 14:59:06 +01:00

11 lines
631 B
Plaintext

According to the Java ``Comparable.compareTo(T o)`` documentation:
{quote}
It is strongly recommended, but not strictly required that ``(x.compareTo(y)==0) == (x.equals(y))``.
Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact.
The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
{quote}
If this rule is violated, weird and unpredictable failures can occur.
For example, in Java 5 the ``PriorityQueue.remove()`` method relied on ``compareTo()``, but since Java 6 it has relied on ``equals()``.