Having the following simple class structure:
class A {
}
class B extends A {
}
class C extends B {
}
I\'m creating an ArrayList to keep o
List super B>
allows you to use Lists of any supertype of B, i.e. list5 = new ArrayList<A>();
or list5 = new ArrayList<Object>();
You can safely add B (and subtypes) to every list that use supertypes of B, but you can not add any supertype of B. Imagine this:
public void myAdd(List super B> lst) {
lst.add(new Object()) //this is a supertype of B (compile time error)
}
...
ArrayList list = new ArrayList();
myAdd(list); //tries to add Object to a list of type A