int的哈希码 [英] Hashcode of an int

查看:144
本文介绍了int的哈希码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始类型的哈希码是什么,例如int?

What is the hashcode of a primitive type, such as int?

例如,让我们说num是一个整数。

for example, let's say num was an interger.

int hasCode = 0;

if (num != 0) {
  hasCode = hasCode + num.hashCode();
}


推荐答案

int 的hashCode 最自然的选择是使用 int 本身。一个更好的问题是如何使用 c> long ,因为它不适合 int -sized哈希码。你的最佳来源—以及所有 hashCode 相关的问题—将是有效的Java

For the hashCode of an int the most natural choice is to use the int itself. A better question is what to use for the hashCode of a long since it doesn't fit into the int-sized hashcode. Your best source for that—and all hashCode-related questions—would be Effective Java.

这篇关于int的哈希码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆