11. public void addStrings(List list) { 
12. list.add(”foo”); 
13. list.add(”bar”); 
14. } 
What must you change in this method to compile without warnings? 
A. add this code after line 11: 
    list = (List<String>) list; 
B. change lines 12 and 13 to: 
    list.add<String>(”foo”); 
    list.add<String>(”bar”); 
C. change the method signature on line 11 to: 
    public void addStrings(List<? extends String> list) { 
D. change the method signature on line 11 to: 
    public void addStrings(List<? super String> list) { 
E. No changes are necessary. This method compiles without warnings. 

解决方案 »

  1.   

    会有警告的,你把代码放入Eclipse就知道了。会警告你参数: List list 没有定义泛型。
      

  2.   

    那像这样的,List list= new ArrayList();也没定义参数,怎么也行啊?
      

  3.   


    语法并没错误,但是跟你顶楼的问题一样,有警告啊:Multiple ers at this line
    - The value of the local variable list is not used
    - List is a raw type. References to generic type List<E> should be parameterized
    - ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
      

  4.   

    What must you change in this method to compile without warnings?对于支持泛型语法的编译器,如果你该使用泛型而没有使用泛型,编译时会有warning.在IDE里也可以看到
      

  5.   

    List<? super String> list
    请问一下,这句是什么意思呀?
      

  6.   

    在Myeclipse 中试一下就知道了,集合中用泛型是为了安全