@
aznfy 第二个里面 T 只是 Comparable<T>的子类 如果你的 SecondClass 实现了 Comparable<E>那就不行了
下面代码可以编译通过
public class FirstClass<E extends Comparable<E>, T extends SecondClass<E> & Comparable<T>> {
public void compare(T t1, T t2) {
t1.compareTo(t2);
}
public static void main(String[] args) {
FirstClass<String, ThirdClass> firstClass = new FirstClass<>();
ThirdClass t1 = new ThirdClass(1);
ThirdClass t2 = new ThirdClass(2);
firstClass.compare(t1, t2);
}
static class ThirdClass extends SecondClass<String> implements Comparable<ThirdClass> {
int i;
public ThirdClass(int i) {
this.i = i;
}
@
Override public int compareTo(ThirdClass o) {
return 0;
}
}
}