java - int 的哈希码

标签 java int hashcode primitive

什么是原始类型的哈希码,例如 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/

相关文章:

c# - 相同的 GUID 可以产生不同的哈希码吗?

java - java程序出错时如何保持运行

java - Spring,组件扫描导致NamespaceHandler周围的FatalBeanException

java - 为什么克隆阵列这么慢?

java - 速度 : four ints or one int with many operations

java - 当 toString() 和 hashCode() 被覆盖时,如何在 java 中获取对象的 "object reference"?

java - 在 Eclipse 的首选项中打开调试时出错

Python:将字母数字字符串可逆地编码为整数

c - 如何确定宽度为 `int` 和 `unsigned` 两倍的整数类型?

.net - 'int GetHashCode' 是不是有点短视?