Comparable
The standard interface a type implements to define its natural ordering, through a compareTo method.
In more detail
compareTo returns a negative number, zero or a positive number when this value is less than, equal to or greater than the other. Sorting and generic methods bounded by Comparable rely on it.
Example
left.compareTo(right) >= 0 ? left : rightRelated terms
- bounded type parameter — A type parameter restricted to types that support a capability, such as T extends Comparable<T>, so the code can call that capability.
- interface (Java) — A Java type that lists operations without fixing how they are carried out, so different classes can provide their own implementations.
Taught in
- Generics Fundamentals — Modern Java: Virtual Threads & High-Throughput Services