I was reading java generics, I came across an interesting query. My question is as follows.
For an upper bounded wildcard
public static void printList(List<? extends Number> list) { for (int i = 0; i < 10; i++) { list.add(i);// gives compilation error } }
For a lower bounded wildcard
public static void printList(List<? super Integer> list) { for (int i = 0; i < 10; i++) { list.add(i);// successfully compiles } }
I am confused with this because looking at the Sun Oracle documentation I understand that the code should compile for point 1 as well
Upper Bound Wildcard Lower Bound Wildcard
Can anyone please help me to understand this?