什么是原始类型的哈希码,例如 int?
例如,假设 num 是一个整数。
int hasCode = 0;
if (num != 0) {
hasCode = hasCode + num.hashCode();
}
最佳答案
取自Integer.class
源代码:
/**
* Returns a hash code for this {@code Integer}.
*
* @return a hash code value for this object, equal to the
* primitive {@code int} value represented by this
* {@code Integer} object.
*/
public int hashCode() {
return value;
}
其中value
是整数的值。
关于java - int 的哈希码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890805/