How to add an integer element to ArrayList of wildcards in Generics?

后端 未结 5 408
忘了有多久
忘了有多久 2021-01-17 00:44

I have a ArrayList generic wildcards type, which is taking Number as extends. I am trying to add the integer values to the ArrayList.

Buts it\'s giving me an error

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 01:32

    you can use;

     ArrayList  numberList = new ArrayList();
     Number number = 1;
     numberList.add(number);
    
     or
    
     numberList.add(1);
    

提交回复
热议问题