class GenericDemo
{
public static void main(String[] args)
{
ArrayList<Person> al = new ArrayList<Person>();
al.add(new Person("abc1"));
al.add(new Person("abc2"));
al.add(new Person("abc3"));
printColl(al);
}
public static void printColl(ArrayList<? super Student>/*<? extends Person>为什么这样就可以*/ al)
{
Iterator<? super Student>/*<? extends Person>为什么这样就可以*/ it = al.iterator();
while (it.hasNext())
{
System.out.println(it.next().getName());
}
}
}
class Person
{
private String name;
Person(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
class Student extends Person
{
Student (String name)
{
super(name);
}