How can I add to List<? extends Number> data structures?

前端 未结 6 976
暗喜
暗喜 2020-11-22 02:19

I have a List which is declared like this :

 List foo3 = new ArrayList();

I tried to add 3 to foo3.

6条回答
  •  灰色年华
    2020-11-22 03:20

    "List '<' ? extends Number> is actually an upper bound wildcard !

    The upper-bounded wildcard says that any class that extends Number or Number itself can be used as the formal parameter type: The problem stems from the fact that Java doesn’t know what type List really is. It has to be an EXACT and UNIQUE Type. I hope it helps :)

提交回复
热议问题