这是因为
hashCodefor
int[]不会被覆盖。即使条目
int[]相同
hashCode,也没有理由为什么的两个实例应该具有相同的值。
试试这个:
System.out.println(new int[] {1, 2}.hashCode());System.out.println(new int[] {1, 2}.hashCode());您几乎可以肯定会看到两个不同的整数。
Objects.hash与数组一起使用的一种好方法是传递
Arrays.hashCode(array)而不是实际数组。在您的情况下,您可以执行以下操作:
Objects.hash("getDemoCache", "1", Arrays.hashCode(new int[]{1, 2}))


