Does Scala's BigDecimal violate the equals/hashCode contract?
Posted
by oxbow_lakes
on Stack Overflow
See other posts from Stack Overflow
or by oxbow_lakes
Published on 2009-08-28T08:02:31Z
Indexed on
2010/03/18
23:01 UTC
Read the original article
Hit count: 503
As the Ordered
trait
demands, the equals
method on Scala's BigDecimal
class is consistent with the ordering. However, the hashcode is simply taken from the wrapped java.math.BigDecimal
and is therefore inconsistent with equals.
object DecTest {
def main(args: Array[String]) {
val d1 = BigDecimal("2")
val d2 = BigDecimal("2.00")
println(d1 == d2) //prints true
println(d1.hashCode == d2.hashCode) //prints false
}
}
I can't find any reference to this being a known issue. Am I missing something?
© Stack Overflow or respective owner