lev*_*vik 11
Java允许您覆盖hashCode()
类的方法以使用散列算法,该算法不仅适用于您的应用程序,而且适用于您的各种类型:
public class Employee {
private int id;
// Default implementation might want to use "name" for as part of hashCode
private String name;
@Override
public int hashCode() {
// We know that ID is always unique, so don't use name in calculating
// the hash code.
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9469 次 |
最近记录: |