// The new way: works in Java 5.0+. Interface takes a type parameter. class Pair implements Comparable { Double x, y; public Pair(double x, double y) { this.x = new Double(x); this.y = new Double(y); } public int compareTo(Pair other) { if ( this.x.equals(other.x) ) { return this.y.compareTo(other.y); } else { return this.x.compareTo(other.x); } } }