the edit makes it worse, the code is now inconsistent with the error message and it's a different question (it won't compile even without the nesting)
–
Michael BorgwardtJun 9 '11 at 14:08

hm, I was acting too quick you're right, about being inconsistent with the error message. So now I'll have to edit the error message as well. but the question remains, and you gave a fair answer, thx
–
bpgergoJun 9 '11 at 14:12

People may want to read up on C#'s covariant/contravariant declarations for generic interfaces and delegates which was added in 4.0. That is one way to "solve" this problem (well it changes the problem first)
–
VooJun 9 '11 at 14:20

@Voo see a very old paper "On Variance-Based Subtyping for Parametric Types". the two approaches were analyzed for their pros/cons. Java went one way, C# went another way, but there is nothing new. C#'s approach appears simple in simple case, but the complexity easily becomes unmanageable, as the paper stated. (I don't appreciate C# people present it as something they invented and magical without flaw)
–
irreputableJun 9 '11 at 14:36

@irreputable Will look at the paper if I have time for some surely highly non trivial talk about co/contravariance ;) And well Generics are complicated to begin with but being able to express co/contravariance can be useful sometimes. But sure nothing for the faint-hearted. But then Java didn't have a choice to begin with - I don't see how that could be implemented backwards compatible. But then I think everybody agrees that Java's implementation is horrible as is, so really no good idea to add anything on top of it
–
VooJun 9 '11 at 15:50

lo.get(0).add(new Object()); would raise an error, since you try to add an object to a list of string.
–
clapasOct 3 '14 at 14:51

means that the wildcard could be substituted only for those objects, that are subclass of Object class.

List<List<? extends Object>> ll = new ArrayList<List<Object>>();

gives you error of type mismatch because you are trying to assign a ArrayList of List of object of java class Object to a List that contains the List of any type of objects that are subclass of java class Object.

When assigning to a variable (List<T>) with a non-wildcard generic type T, the object being assigned must have exactly T as its generic type (including all generic type parameters of T, wildcard and non-wildcard). In your case T is List<? extends Object>, which is not the same type as List<Date>.

What you can do, because List<Date> is assignable to List<? extends Object>, is use the wildcard type: