"sottoclassi" di AnyVal
non si comportano correttamente dal punto di vista di hashing:
scala> 1.0.hashCode
res14: Int = 1072693248
naturalmente questo è inscatolato ad una chiamata a:
scala> new java.lang.Double(1.0).hashCode
res16: Int = 1072693248
Potremmo preferiamo che sia :
scala> new java.lang.Double(1.0).##
res17: Int = 1
scala> 1.0.##
res15: Int = 1
Dobbiamo xpetto questo dato che lo int
1 è anche il double
1. Ovviamente questo problema non si verifica in Java. Senza di essa, avremmo questo problema:
Set(1.0) contains 1 //compiles but is false
fortuna:
scala> Set(1.0) contains 1
res21: Boolean = true
fonte
2012-01-30 18:10:06
'1.0 hashCode' v' '1.0 ## v' 1 hashCode' v '1 ##' - http://www.scala-lang.org/api/current/ scala/Any.html – Debilski
Un po 'fuori programma, ma è possibile cercare tali simboli usando [SymbolHound] (http://www.symbolhound.com/). –
Ah ok. Quindi, '1.hashCode'' ==' '1. ##', e '1.2.hashCode'' == '' 1.2. ## '. L'unica cosa che si comporta diversamente è '1.0.hashCode''! = '' 1.0. ## '(quindi' ## 'è più adatto per confrontare i numeri). –