Can anyone give me an explanation on the following..
List<? extends Shape> typeList = new ArrayList<>();
List<Shape> shapeList = new ArrayList<>();
typeList.addAll(shapeList); //1
typeList = shapeList; //2
Here 'line 1' will not compile because typeList is defined to take some class that extends Shape. However the compiler doesn't know which class. Therefore the compilation fails.
The same logic applies to 'line 2'. How shapeList can be assigned to typeList? Why this line is not giving compilation error?