Comparables and Comparators
What is it?
CompareTo can't return anything you want!
Defining a Comparable subclass
public class MyComparable implements Comparable<MyComparable> {
public int foo;
...
/** Instance method that has nothing to do with comparable */
public void doSomething() {
...
}
/** Comparable method used to compare objects of this type */
public int compareTo(Object o) {
MyComparable mc = (MyComparable) o;
return ...
}
}Comparators
How is it different from Comparables???
Last updated