为什么编译:
class MaxMin<E extends Comparable<E>>
{
E max=null;
E min=null;
}
...但这不是吗?
class MaxMin<E implements Comparable<E>>
{
E max=null;
E min=null;
}
最佳答案
通用类型边界仅指定extends
和super
。
引用Java Generics Tutorial (强调我的)
To declare a bounded type parameter, list the type parameter's name, followed by the extends keyword, followed by its upper bound, which in this example is Number. Note that, in this context, extends is used in a general sense to mean either "extends" (as in classes) or "implements" (as in interfaces)
关于java - 为什么泛型绑定(bind) "E implements I"会导致编译器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8029214/