How come the List in the main method below compiles?
class Breakfast {
}
class Drink extends Breakfast {
}
class Juice extends Drink {
}
class Food extends Breakfast {
}
class Bread extends Food {
}
public static void main(String[] args) {
Object object = new Object();
Drink drink = new Drink();
Juice juice = new Juice();
Bread bread = new Bread();
List<? super Drink> firstList = Arrays.asList(object, drink, juice, bread);
List<?> secondList = Arrays.asList(object, drink, juice, bread);
List<? extends Drink> thirdList = Arrays.asList(drink, juice, bread); //DOESN'T COMPILE
}
Seeing as bread is not a superclass of Drink? What is the rule that allows the compilation of the first and second lists but not the third? And if so then what are the main differences between
<?>
and
<? super Drink>
Thanks!