其实我也很好奇,有些函数- public int compare(Object o1, Object o2) {
- if(o1 instanceof Employee1 && o2 instanceof Employee1){
- Employee1 e1 = (Employee1)o1;
- Employee1 e2 = (Employee1)o2;
- MyDate birth1 = e1.getBirthday();
- MyDate birth2 = e2.getBirthday();
- if(birth1.getYear() != birth2.getYear()){
- return birth1.getYear() - birth2.getYear();
- }else{
- if(birth1.getMonth() != birth2.getMonth()){
- return birth1.getMonth() - birth2.getMonth();
- }else{
- return birth1.getDay() - birth2.getDay();
- }
- }
- }
- return 0;
- }
复制代码
既然函数中有其他的return语句了,为什么还要在末尾加一个return 0呢? |