- public int compare(Object o1, Object o2) {
- if(o1 instanceof Student1 & o2 instanceof Student1){
- Student1 s1 = (Student1)o1;
- Student1 s2 = (Student1)o2;
- if(s1.getAge() > s2.getAge()){
- return -1;
- }else if(s1.getAge() < s2.getAge()){
- return 1;
- }
- }
- return 0;
- }
复制代码
这段代码里如果o1或者o2不是student1的对象,是不是就返回它俩个相等啊?
有点晕乎了..... |
|