Direct Known Satisfying Classes: Character, String
Direct Known Satisfying Interfaces: Scalar<Other>

The general contract for values whose magnitude can be compared. Comparable imposes a total ordering upon instances of any type that satisfies the interface. If a type T satisfies Comparable<T>, then instances of T may be compared using the comparison operators <, >, <=, >=, and <=>.

The total order of a type must be consistent with the definition of equality for the type. That is, there are three mutually exclusive possibilities:

  • x<y,
  • x>y, or
  • x==y
By: Gavin
Inherited Attributes
Attributes inherited from: Object
compareSource Code
shared formal Comparison compare(Other other)

Compares this value with the given value. Implementations must respect the constraints that:

  • x==y if and only if x<=>y == equal (consistency with equals()),
  • if x>y then y<x (symmetry), and
  • if x>y and y>z then x>z (transitivity).
See also: equals
Inherited Methods
Methods inherited from: Object