Why Object#hashCode() returns int instead of long

后端 未结 3 1105
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 04:54

why not:

public native long hashCode();

instead of:

public native int hashCode();

for higher chance of a

3条回答
  •  甜味超标
    2020-12-03 05:34

    Because the maximum length of an array is 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.

提交回复
热议问题