Fancy generics capture collision

后端 未结 5 1291
星月不相逢
星月不相逢 2021-01-05 07:19

Please give me a hint as to what is going on here:

List a = new ArrayList();
List b = new Array         


        
5条回答
  •  粉色の甜心
    2021-01-05 07:50

    Don't use the ? wildcard. It means "Some specific type I don't know", and since you don't know the type, you can't add anything to the list. Change your code to use List and everything will work.

    This is fast becoming the most frequently asked Java question, in a hundred variations...

提交回复
热议问题