class GenericDemo8
{
public static void main(String[] args)
{
ArrayList<Person> al=new ArrayList<Person>();
al.add(new Person("zhangsan1",3));
al.add(new Person("zhangsan2",3));
al.add(new Person("zhangsan3",3));
printColl(al);
}
public static void printColl(ArrayList <? extends Person> al)
{
Iterator<? extends Person> it=al.iterator();
while (it.hasNext())
{
//System.out.println(it.next().getName());
System.out.println(it.next().getAge());
}
}
}
注解Person类与Student类已经写好
问题是,我想同时输出name和age要怎么办?跪求答案啊!!! |
|