I don't understand. Why will this not compile? Just adding Beagles works fine. c is declared as super Beagle which should include Dog.
public class Hello<T> {
public static void main(String[] args){
Dog d = new Dog();
ArrayList<? super Beagle> c = makeArrayList(d);
c.add(new Beagle());
c.add(new Beagle());
c.add(new Dog());
}
public static <G extends Animal> ArrayList<G> makeArrayList(G g){
ArrayList<G> genlist = new ArrayList<>();
genlist.add(g);
return genlist;
}
}
class Animal{public void makeSound(){
System.out.println("Sound!");
}
}
class Dog extends Animal{}
class Beagle extends Dog{}