Item
(without any type argument) is a raw type, so:
We could pass any kind of
Item
toItem.compareTo
. For example, this would compile:new Item<String>().compareTo(new Item<Integer>())
The method
o.getT()
returnsComparable
instead ofT
, which causes the compilation error.In the example under the 1st point, after passing
Item<Integer>
toItem.compareTo
, we would then erroneously pass anInteger
toString.compareTo
. The compilation error prevents us from writing the code which does that.
I think you just need to remove the raw types:
public class Item<T extends Comparable<T>>
implements Comparable<Item<T>> {
...
@Override
public int compareTo(Item<T> o) {
return getT().compareTo(o.getT());
}
}