import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class PersonText {
public static void main(String[] args){
TreeSet ts = new TreeSet();
ts.add(new Student("zhawern",223));
ts.add(new Student("zhaan",243));
ts.add(new Student("zhandgan",23));
ts.add(new Student("zhangaan",63));
}
}
class Student implements Comparable
{
private String name;
private int age;
Student(String name,int age){
this.name = name;
this.age =age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public int comparaTo(Object obj){
if(obj instanceof Student){
throw new RuntimeException();
}
Student s = (Student)obj;
return this.name.compareTo(s.name);
}
}
这个程序哪里出错误了 |
|