import java.util.*;
class GenericDemo1
{
public static void main(String[] args)
{
ArrayList<Student> al=new ArrayList<Student>();
al.add(new Student("abc1"));
al.add(new Student("abc2"));
al.add(new Student("abc3"));
ArrayList<Person> al1=new ArrayList<Person>();
al1.add(new Person("abc11"));
al1.add(new Person("abc21"));
al1.add(new Person("abc31"));
printColl(al1);
}
public static void printColl(ArrayList<? super Student> al)
{
Iterator<? super Student> 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);
}
}
运行结果错误,it.next()找不到符号??苦恼中,希望各位大虾帮忙解决!!!
|
|