Creating generic list of type object and adding a string
I'm trying to create a Generic list that will hold any type of items that
inherits from Object(I assume every object is of type object).
But, in the case below, when I try to add a String(Inherits from Object),
it shows a error in Eclipse
Error:-The method add(capture#1-of ? extends Object) in the type
List<capture#1-of ? extends Object> is not applicable for the arguments
(String)
List<? extends Object> alist = new ArrayList<Object>();
alist.add("USA");
Can someone explain why I get this error?
No comments:
Post a Comment