小编MIZ*_*FAT的帖子

为什么两个具有相同值的原始双精度数具有两个不同的identityHashCode?

我了解到所有具有相同值的图元都具有相同的值,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原因?

java double

2
推荐指数
1
解决办法
124
查看次数

标签 统计

double ×1

java ×1