I'd like to use a generic list, but the initialization method only returns a List
.
The following code works well:
List tmpColumnList = aMethodToInitializeTheColumnList();
tmpColumnList.add("ANICELITTLECOLUMN");
Java accuses that I'm using a raw type and I should paramerize the list.
So I added the question mark parameterize this list.
List<?> tmpColumnList = aMethodToInitializeTheColumnList();
tmpColumnList.add("ANICELITTLECOLUMN");
Problem is: Now the add(..)
method doesn't work anymore.
I cannot assure that the list only contains String
s as aMethodToInitializeTheColumnList()
is not implemented in my code.
What is my mistake?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…