Understanding wildcards in Java generics

后端 未结 7 1631
不思量自难忘°
不思量自难忘° 2020-12-31 11:07

I\'m not sure why the last statement in the following code is illegal. Integer should be a subtype of ?, so why can\'t I assign it to b

7条回答
  •  再見小時候
    2020-12-31 12:00

    Integer is not a subtype of ? (necessarily). ? is a wildcard; you should interpret it as meaning "unknown".

    So a List is not the same as a List. You can add anything you like to a List.

    提交回复
    热议问题