I want to compare to variables, both of type T extends Number. Now I want to know which of the two variables is greater than the other or equal. Unfortunately I
This should work for all classes that extend Number, and are Comparable to themselves.
class NumberComparator implements Comparator {
public int compare(T a, T b){
if (a instanceof Comparable)
if (a.getClass().equals(b.getClass()))
return ((Comparable)a).compareTo(b);
throw new UnsupportedOperationException();
}
}