Consider the following snippet:
List<Double> doubleList = null;
List<Integer> integerList = null;
List<Number> numberList = null;
//expression:1
List<? super List<? super Integer>> superDoubleList = Arrays.asList(doubleList, integerList,numberList);
//expression:2
//here doubleList will cause compilation error
List<? extends List<? super Integer>> extendsDoubleList = Arrays.asList(integerList,numberList);//doubleList
- Here I am trying to understand how to interpret these two statements
- Expression:1
- Here we say that the List on the RHS must be such that all the elements of the list will satisfy the condition
? super List<? super Integer>
- but
doubleList
/integerList
/numberList
are not satisfying this condition anyhow - as we expect a type that is a supertype ofList<? super Integer>
. - Still why are we not getting compilation error here?
- Here we say that the List on the RHS must be such that all the elements of the list will satisfy the condition
- Expression:2
- Here we expect that the elements on the RHS must be the
subtype of List<? super Integer>
- so
doubleList
intuitively can be seen as a candidate that can satisfy the condition. - Why still I am getting compilation error if I include
doubleList
in theArrays.asList
expression?.
- Here we expect that the elements on the RHS must be the
- Expression:1
Not sure if I am interpreting the expressions in the right way - and what is wrong possibly that logically it does not seem to fit the explanation I gave above?