This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Because when you have (first example) a List <? super Integer> al = new ArrayList<Number>();
Then the list "al" contains only numbers. This is type safe, you can only add Integers to this list, and what you get out of the list are always Objects. And because you can say Object o = new Integer(3); this should work.
By the way: List <? super Integer> al2 = new ArrayList<Object>(); would work just the same.
But when you have (second example) List <? extends Number> al = new ArrayList<Integer>();
You may think in the first place that add(3);
would be fine, but what you add to this list would always be of type Number, so you also could try to add(3.0);
And further you also can rereference "al" to another List: al = new ArrayList<Double>(); this is allowed, and therefore it is not allowed to add anything (except null) to this kinds of lists.