Comparable Interface
Comparable Interface
- The Comparable interface is used to compare two objects, and contains the method compareTo().
-
compareTo() takes a parameter of type Object.
- We will revisit this in the Generics lab.
- Comparison is performed between the calling object (the object implementing this interface) and the parameter Object.
-
compareTo() should compare and determine if the calling object is greater,
less than, or equal to the parameter object passed in.
- compareTo() returns a positive integer, a negative integer, or 0 (zero), respectively.