本帖最后由 何伟超 于 2014-2-18 10:31 编辑
import java.util.*;
class students implements Comparable//定义students类
{
private String name;
private int age;
private String por;
students (String name,int age,String por)
{
this.name = name;
this.age = age;
this.por = por;
}
public String getname()
{
return name;
}
public int getage()
{
return age;
}
public String getpor()
{
return por;
}
}
class setmap
{
public static void main(String[] args) //主函数
{
ArrayList st =new ArrayList();
st.add(new students("lishi1",22,"sum"));
st.add(new students("lishi2",21,"pub"));
st.add(new students("lishi3",12,"sum"));
st.add(new students("lishi4",32,"eng"));
itera(st);调用迭代器函数。
}
public static <students> void itera(ArrayList<students> ar)//迭代器函数
{
Iterator<students> it = ar.iterator();
while(it.hasNext())
{
students ss = it.next();
System.out.println(ss.getname());//问题。这里的SS老报错,显示ss为obj类没有getname()方法!!!!
setmap.java:83: 找不到符号
符号: 方法 getname()
位置: 类 java.lang.Object
System.out.println(ss.getname());
}
}
}
|