我有一个名为 Employee 的 pojo,现在我想创建一个用户定义的集合,并将其放在地图上。请告诉我如何实现这一目标。
public class Employee {
String name,job;
int salary;
public Employee(String n , String j, int t) {
this.name= n;
this.job=j;
this.salary= t;
}
@Override
public int hashCode() {
return name.hashCode()+job.hashCode()+salary;
}
@Override
public boolean equals(Object obj) {
Employee e = (Employee) obj;
return this.name.equals(e.name) && this.job.equals(e.job)
&& this.salary == e.salary;
}
}