这段代码执行结果为何为0
这是一个接口的源码,运行时遇到点奇怪的问题,如下代码,其中红色代码是啥意思,没见过这种写法,请教高手指点:import java.util.*;
public class EmployeeSortTest {
public static void main(String[] args) {
Employee[] staff=new Employee[3];
staff[0]=new Employee("man1",1000);
staff[1]=new Employee("b",2000);
staff[2]=new Employee("c",500);
Arrays.sort(staff);
for(Employee e:staff)
{
System.out.println("姓名"+e.getName()+" 薪水="+e.getSalary());
}
}
}
class Employee
implements Comparable {
private String name;
private double salary;
public Employee(String n, double s) {
String name = n;
double salay = s;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
public int compareTo(Employee other) {
if (salary < other.salary)
return -1;
if (salary > other.salary)
return 1;
return 0;
}
public int compareTo(Object o) {
return 0;
}
}
运行结果:
姓名null 薪水=0.0
姓名null 薪水=0.0
姓名null 薪水=0.0