Nested Generics with Wildcards

后端 未结 5 993
小鲜肉
小鲜肉 2020-12-18 09:32

Why does this work:

List list = new LinkedList();

while this gives a type dismatch error:

List

        
5条回答
  •  Happy的楠姐
    2020-12-18 10:29

    I know this is and post, but I don't seem how the answers fixed c0d3x's problem.

    If you do

    List> list = new LinkedList>();
    

    How is he gonna call this method for each inner Integer list in the outer list?

    public void doSomeThingWithAIntegerList(List list){
        for(Integer i : list){
            // use it for some purpose
        }
    }
    

提交回复
热议问题