I am a novice, I met a problem, do not understand, as follows:
class Animal {}
class Cat extends Animal {}
class Garfield extends Cat {}
public class Demo {
public static void main(String[] args) {
List<? super Cat> list = new ArrayList<>(); // list can include cat and animal
list.add(new Cat()); // perfect !!
list.add(new Garfield()); // wait... why can ??
list.add(new Animal()); // wait... why can't ??
}
}
Thank you very much!