List<? extends Integer> list = new ArrayList<Integer>();
for (Integer element : list) {
System.out.println(element);
List<? super Integer> list = new ArrayList<Integer>();
for (Integer element : list) {
System.out.println(element);
For the first three lines as Case 1 using extends it compiles fine. But for Case 2 of next three lines, it says incompatible types. Found Object, required Integer. My confusion is ? extends Integer being anything that is an Integer or sub of it works.
But why in Case 2 where ? super Integer means anything that is an Integer or a superclass of Integer doesn't work when it's elements ar being given to an Integer element in the for loop??