错误:需要class、interface或enum

郁林君 郁林君 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.util.*;
class GenericDemo6
{
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<Person> al)
{
Iterator<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;
}
}

为什么会提示这样的,我明明已经声明了类型了
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
郁林君
Java SE 62,621 成员 307,251 内容