// same as Box but T extends Comparable so that we can compare T's, and ComparableBox implements Comparable so that // we can compare Box's. Notice we are allowing for two different types of comparisons, one is for the instance datum // itself (item) and one is for two ComparableBoxes. public class ComparableBox> implements Comparable { private T item; // our instance datum is an Object of type T which must be Comparable public ComparableBox(T item) // constructor { this.item=item; } public T get() // accessor { return item; } public void set(T item) // mutator { this.item=item; } public int compareTo(ComparableBox item2) // comareTo to implement Comparable for Box { return compareTo(item2.get()); // we are comparing this to item2, so T must implement Comparable as well } @Override // here we have a compareTo for a T, not a ComparableBox, this is public int compareTo(T item2) // used to actually get the comparison between two T's { return item.compareTo(item2); } public String toString() { if(item!=null) return ""+item; else return "not set"; } }