JAVA day15

 TreeSetDemo.java

 1 public int compareTo(Object obj)     
 2 {            
 3     if(!(obj instanceof Student))
 4         throw new RuntimeException("不是学生对象");   
 5      Student stu = (Student)obj;
 6             
 7     if((this.age == stu.age) && !this.name.equals(stu.name)) 
 8         return (this.name.compareTo(stu.name));
 9     else
10         return (this.age-stu.age); 
11 }            
12   
posted @ 2014-01-07 11:45  静静静流  阅读(130)  评论(0编辑  收藏  举报