From Comparable
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."
As @ZouZou mention
The natural ordering for a class C is said to be consistent with
equals if and only if e1.compareTo(e2) == 0 has the same boolean value
as e1.equals(e2) for every e1 and e2 of class C. Note that null is not
an instance of any class, and e.compareTo(null) should throw a
NullPointerException even though e.equals(null) returns false.
That means they are not interchangable.
An example where this happen in java api is in BigDecimal
import java.math.BigDecimal;
public class Test{
public static void main(String args[]) {
BigDecimal big = BigDecimal.ZERO;
BigDecimal zero = new BigDecimal("0.00");
System.out.println("Compare "+ (big.compareTo(zero) == 0) ); //prints true
System.out.println("Equals "+big.equals(zero)); // prints false
}
}