I am trying to add an element in a list where the list type parameter is a wildcard that extends Question
ArrayList<? extends Question> id = new ArrayList<? extends Question>();
id.add(new Identification("What is my name?","some",Difficulty.EASY));
map.put("Personal", id);
Where identification is a subclass of Question. QUestion is an abstract class.
it is giving me this error
On Line #1 Cannot instantiate the type ArrayList<? extends Question>
And on Line #2
The method add(capture#2-of ? extends Question) in the type ArrayList<capture#2-of ? extends Question> is not applicable for the arguments (Identification)
Why is it showing an error like that? What is causing it? And how would I fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…