import java.util.LinkedList;
class GenericInseption{
public static void main(String[] args){
LinkedList<LinkedList<Dad>> listOfLists = new LinkedList<>();
LinkedList<Dad> list = new LinkedList<>();
listOfLists.add(list);
test(listOfLists);//error
}
private static void test(LinkedList<LinkedList<? extends Person>> listOfLists){
for(LinkedList<? extends Person> list : listOfLists){
for(Person person : list){
//peform operation on person objects
}
}
}
}
class Person{}
class Dad extends Person{}
error
GenericInseption.java:7: error: method test in class GenericInseption cannot be applied to given types;
test(listOfLists);//error
^
required: LinkedList<LinkedList<? extends Person>>
found: LinkedList<LinkedList<Dad>>
reason: argument mismatch; LinkedList<LinkedList<Dad>> cannot be converted to LinkedList<LinkedList<? extends Person>>
1 error
but LinkedList< Dad> is a subtype of LinkedList< ? extends Person>
How is this supposed to work?