// the pre-Java 5.0 way: interfaces specify Objects, cast to the right type 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(Object other) { Pair otherp = (Pair) other; if ( this.x.equals(otherp.x) ) { return this.y.compareTo(otherp.y); } else { return this.x.compareTo(otherp.x); } } }