Our Sort.java can be used to sort objects of any class that implements the Comparable interface. SortInt.java can be used with the Sort class for testing purposes. Even simpler is SortString.java.
What if you want to sort the (integers, or strings or whatever) in reverse order? A good object-oriented approach would be to define a new class, identical in all respects to Integer but having a reversed sense of order. A natural approach would be to use inheritance:
public class DecreasingInt extends Integer { public int compareTo(DecreasingInt x) { return -1*super.compareTo(x); } }
For efficiency purposes, Java designates some classes as final. This means they can not be extended. It's a shame, because it precludes an elegant solution to our print-in-reverse-order problem.