如下是一个重写hasCode()的例子:
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
return result;
}
想请问一下prime = 31??有什么作用的??为什么要用31,用别的数字代替行吗??求教,谢谢
|