首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

为什么不能运行啊

2012-12-20 
为什么不能运行啊 求助package Ch01import java.util.TreeSetpublic class Employee {private String na

为什么不能运行啊 求助
package Ch01;

import java.util.TreeSet;

public class Employee {

private String name;
private Double salary;
public Employee(String Name,Double salary){
this.name = Name;
this.salary = salary;
}public String getName() {
return name;
}public void setName(String name) {
this.name = name;
}public Double getSalary() {
return salary;
}public void setSalary(Double salary) {
this.salary = salary;
}
public int compareTo(Employee e){
if(this.salary>e.salary)
return -1;
if(this.salary<e.salary)
return 1;
return 0;
}


public static void main(String[] args) {
TreeSet<Employee> treeset = new TreeSet<Employee>();
treeset.add(new Employee("张三",8000.0));
treeset.add(new Employee("王五",7000.0));
treeset.add(new Employee("马六",7500.0));
for (Employee e:treeset){

System.out.println(e);
}



}
}

[最优解释]
你没有实现Comparable接口啊,你只是写了compareTo()方法.

这样写:

public class Employee implements Comparable<Employee> {}

热点排行
Bad Request.