哈希码和##结果因Double,Float而异

时间:2014-03-30 16:47:25

标签: scala

为什么## of Double,Float结果与hashCode不同

双重例子

scala> var x = 130d
x: Double = 130.0

scala> x.##
res24: Int = 130

scala> x.hashCode
res25: Int = 1080049664

scala> var x = 130f
x: Float = 130.0

scala> x.##
res28: Int = 130

scala> x.hashCode
res29: Int = 1124204544

整数结果相同值

scala> x.##
res30: Int = 130

scala> x.hashCode
res31: Int = 130

字符串结果相同的值

scala> var x = "demo"
x: String = demo

 scala> x.##
 res32: Int = 3079651

 scala> x.hashCode
 res33: Int = 3079651

0 个答案:

没有答案