Krzysztof Koziol posted November 19, 2006 03:15 AM
Object is a super class for all clasess, right?
Yes, but you list is not of type <Object> but of type <? super Strings>.
To a List<? super Strings> you can
1) assign all kinds of lists that are of type String or higher. You assigned a new List<String> to it, you could have also said: List <? super String> list = new ArrayList <Object>();
But even then, you could not add Objects to this list. Because it is only save to add Strings to a List<? super Strings> (or to add subtypes, but subclasses of String do not exist). Because it is allowed (point 1) to also (as you did) assign Lists of type <String> to it, and you cannot add objects that are "higher" than String to a List<String>. So in brief, you can