Nested Generics with Wildcards

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

Why does this work:

List list = new LinkedList();

while this gives a type dismatch error:

List

        
5条回答
  •  盖世英雄少女心
    2020-12-18 10:06

    Try

    List> list = new LinkedList>();
    

    Note: you should be aware that when you use a collection like List you will only be able to use it in "read only" mode (except for adding null values).

提交回复
热议问题