Possible Duplicate:
what is the difference between 'super' and 'extends' in Java Generics
Java Generics WildCard Question: List<? extends A>
I discovered a strange behaviour of Java generics that I can't explain to myself.
If I try the following code, I would expect that it should work
List<? extends Number> list = new ArrayList<>();
list.add(new Integer(2));
list.add(new Float(2.0f));
But this leads to an compiler error.
If I change the first line to
List<? super Number> list = new ArrayList<>();
it works fine for the compiler.
Can anyone explain that to me? What is the difference between ? extends and ? super ?