In the following code snippet it gives compilation error on line 2 but it doesn't on line 3.
List<? extends Object> list1 = new ArrayList<>(); // line 1
list1.add("123"); // line 2
List<? extends Object> list2 = Arrays.asList("123", new Integer(12)); // line 3
If language designers have decided, not to allow to add elements into collection of element type <? extends T>
then it should apply to line 3 too.
What could be the reason for this difference?
Please clarify.