在您的代码中,Team
它只是一个占位符(在这种情况下,称为Type Variable)并且恰好隐藏了 type Team
,而不是引用它。换句话说,该声明等同于:
public class ChampionsLeague<T extends Comparable<T>> extends League<T> {
所以它实际上只是要求一个实现(扩展)Comparable
自身的类(或接口)。所以这个例子:
public class Ball implements Comparable<Ball> {
@Override
public int compareTo(Ball o) { return 0; }
}
// or: public interface Ball extends Comparable<Ball> { }
将工作:
ChampionsLeague<Ball> test = new ChampionsLeague<Ball>();
编辑:
您可能试图实现的一些可能性:
// ChampionsLeague needs a type Comparable to Team
public class ChampionsLeague<T extends Comparable<Team>> extends League<T> {
或者
// ChampionsLeague needs a subtype of Team
// In this case, you can make Team implement Comparable<Team> in its own decl.
public class ChampionsLeague<T extends Team> extends League<T> {