关于Java:Listand lt;对象& Gt是列表LT的子类型?超级数字>

How List<Object> is subtype of List<? super Number>

本问题已经有最佳答案,请猛点这里访问。

阅读Java泛型和集合时。在带super的通配符部分,我提供了一个示例

1
2
3
4
5
public static <T> void copy(List<? super T> dst, List<? extends T> src) {
  for (int i = 0; i < src.size(); i++) {
     dst.set(i, src.get(i));
  }
}

它被称为:

1
Collections.<Number>copy(objs, ints);

以上通话有效,解释如下:

The call is permitted because objs has type List, which is a subtype of List (since Object is a supertype of Number, as required by the wildcard) and ints has type List, which is a subtype of List (since Integer is a subtype of Number, as required by the extends wildcard)

我怀疑ListList的亚型吗?