我了解到所有具有相同值的图元都具有相同的值,identityHashCode所以我想获取identityHashCode一些图元。因此,当我尝试使用具有相同值的2个双精度值时,它给出了不同的结果,identityHashCode我做了以下操作:
int xInt=5;
int yInt=5;
System.out.println(System.identityHashCode(xInt));//output:1867083167
System.out.println(System.identityHashCode(yInt));//output:1867083167
double double1=5;
double double2=5;
System.out.println(System.identityHashCode(double1));//output:1915910607
System.out.println(System.identityHashCode(double2));//output:1284720968
Run Code Online (Sandbox Code Playgroud)
具有相同值的两个整数具有相同的值,identityHashCode但具有相同值的两个双精度值却具有不同的identityHashCode原因?