I am having trouble understanding why the compiler is not allowing the following assignment:
Consumer<Collection<? super Project>> consumer = new Consumer<Collection<Project>>(){};
I generally understand how to use "? super ..." and understand why it works fine in these similar examples:
Consumer<? super Project> projectConsumer = new Consumer<Project>(){};
or
Consumer<? super Project> objectConsumer = new Consumer<Object>(){};
or even
Collection<? super Project> objectCollection = new ArrayList<Object>();
However I don't see how these differ from the first example. Could someone please explain why the first example does not compile?
Consumer<? extends Collection<? super Project>>would work. It's the same reason you can't assign aList<Dog>to aList<Animal>.List<List<?>>: aListthat can accept anyListas an element. For example, it allows both aList<Integer>and aList<String>as elements, at the same time. Neither aList<List<String>>nor aList<List<Integer>>can do that, so neither of them is a subtype ofList<List<?>>.