为什么Object#hashCode()返回int而不是long [英] Why Object#hashCode() returns int instead of long

查看:252
本文介绍了为什么Object#hashCode()返回int而不是long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不:

public native long hashCode();

而不是:

public native int hashCode();

获得唯一哈希码的机会更高?

for higher chance of achieving unique hash codes?

推荐答案

因为数组的最大长度 Integer.MAX_VALUE

由于 hashCode()的主要用途是确定在支持数组中插入对象的槽 HashMap / Hashtable ,哈希码> Integer.MAX_VALUE 将无法存储在数组中。

Since the prime use of hashCode() is to determine which slot to insert an object into in the backing array of a HashMap/Hashtable, a hashcode > Integer.MAX_VALUE would not be able to be stored in the array.

这篇关于为什么Object#hashCode()返回int而不是long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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