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 saying that
ArrayList<? extends Number> numberList = new ArrayList<Number>();
numberList = new ArrayList<Integer>();
numberList.add(100);
The method add(int, capture#2-of ?) in the type
ArrayList<capture#2-of ?>
is not applicable for the arguments (int).
I have tried with this way also, but is giving me the same error
ArrayList<?> numberList = new ArrayList<Number>();
numberList = new ArrayList<Integer>();
numberList.add(100);
The error is :
The method add(int, capture#2-of ?) in the type
ArrayList<capture#2-of ?>
is not applicable for the arguments (int)