public <T extends Comparable<T>> int isSorted(){
return thing1.compareTo(thing2);
}
This new T
is hiding the type parameter of your class (also called T
). They are two different types! And thing1
and thing2
are instances of your class's generic type, which aren't necessarily comparable.
So, you should declare your class's type parameter to be comparable instead:
class GenericPair<T extends Comparable<T>>
And now:
public int isSorted(){
return thing1.compareTo(thing2); // thing1 and thing2 are comparable now
}