I'm trying to write a generic max function that takes two Comparables.
So far I have
public static <T extends Comparable<?>> T max(T a, T b) {
if (a == null) {
if (b == null) return a;
else return b;
}
if (b == null)
return a;
return a.compareTo(b) > 0 ? a : b;
}
This fails to compiles with
The method compareTo(capture#5-of ?) in the type Comparable<capture#5-of ?> is not applicable for the arguments (T)
What I think this is saying is that that the ? in Comparable<?> may be interpreted as one type for parameter a, and another for parameter b, so that they can't be compared.
How do I dig myself out of this hole?