为什么hashcode()返回一个整数而不是长整数? [英] Why does hashcode() returns an integer and not long?

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

问题描述

在Java中,hashcode()方法返回整数而不是long.有什么具体原因吗?

In java, hashcode() method, returns integer instead of long. Is there any specific reason?

推荐答案

好吧,一个很好的理由是基于hashCode的数据结构(HashSetHashMap)使用数组来存储bin和数组仅限于int索引.如果必须将long hashCode()映射到int数组索引,您将一无所获.

Well, one good reason is that the hashCode based data structures (HashSet, HashMap) use an array to store the bins, and arrays are limited to int indices. You will gain nothing by a long hashCode() if you must map it to an int array index.

这篇关于为什么hashcode()返回一个整数而不是长整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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