Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在泛型中使用extends关键字_Java_Generics - Fatal编程技术网

Java 在泛型中使用extends关键字

Java 在泛型中使用extends关键字,java,generics,Java,Generics,我正在尝试这个- List<? extends Integer> l = new ArrayList<Integer>(); l.add(10); ListListList@Codebender.. 对的根据PECS,如果我用super替换extends,这将起作用。但为什么编译器在第一行本身并没有抱怨。l.add(新整数(10))应该可以工作,对吗?可能是自动装箱已经关闭了。@Kenney不,不会的work@MohammadAdil,因为ArrayList是ListW

我正在尝试这个-

List<? extends Integer> l = new ArrayList<Integer>();
l.add(10);

List
List
List@Codebender.. 对的根据PECS,如果我用super替换extends,这将起作用。但为什么编译器在第一行本身并没有抱怨。
l.add(新整数(10))
应该可以工作,对吗?可能是自动装箱已经关闭了。@Kenney不,不会的work@MohammadAdil,因为
ArrayList
ListWell的有效对象(子类型),在这种情况下,我能否将
MyImaginaryInteger
添加到
ListNo,因为它可能是
列表
The method add(int, capture#1-of ? extends Integer) in the type List<capture#1-of ? extends Integer> is not applicable for the arguments (int)