As required Ordered trait, the method equalsin the Scala class BigDecimalis consistent with order. However, the hash code is simply taken from the wrapped one java.math.BigDecimaland is therefore incompatible with peers.
Ordered
trait
equals
BigDecimal
java.math.BigDecimal
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 not find a link to this known issue. Did I miss something?
The people on the Scala user mailing list seem to agree that this is a mistake. I guess this has not been so far, because no one has ever used BigDecimalas a key in the hash structure. It was reported as bug # 2304
: ! , , , .
equals/hashCode. , d1.equals(d2) . , d1.equals(d2) false. ?
hashCode
d1.equals(d2)
, "2" - , "2.00"; . , (2 == 2.00), (0!= 2).
, , Java BigDecimal equals . , Java, , .
Source: https://habr.com/ru/post/1716281/More articles:Simulate a network before a specific process - windowsFree NHibernate table for hierarchy matching task - c #C and #defines - cThe string has no links in the C # structure with layout - c #Mysql lock wait timeout exceeded, try restarting transaction - mysqlWhy does calling close () in the InitialContext interrupt JNDI for all future searches (Glassfish)? - javaVisual C ++ - Why worry about debugging mode? - c ++How to define dynamic and precisely snapped bindings to Guice? - javaShow progressive jpeg in IE - internet-explorerHow can I get Wordpress archives by username? - phpAll Articles