62,614
社区成员
发帖
与我相关
我的任务
分享
@Override
public int hashCode()
{
return 7 * region.hashCode() + 9 * location.hashCode() + 13 * department.hashCode();
}
import java.util.HashMap;
import java.util.Map;
public class TestRegex extends Object {
/**
* @param args
*/
public static void main(String[] args) {
Map map = new HashMap();
map.put(new Employee("a", "shanghai", "zhengfu"), null);
map.put(new Employee("a", "shanghai", "zhengfu"), null);
System.out.println(map.size());
}
}
class Employee {
String region;
String location;
String department;
public Employee(String _region, String _location, String _department) {
this.region = _region;
this.location = _location;
this.department = _department;
}
public boolean equals(Object obj) {
if (!(obj instanceof Employee)) {
return false;
}
Employee p = (Employee) obj;
return p.region.equalsIgnoreCase(region)
&& p.location.equalsIgnoreCase(location)
&& p.department.equalsIgnoreCase(department);
}
@Override
public int hashCode()
{
return region.hashCode() + location.hashCode() + department.hashCode();
}
}