Edit: This issue no longer exists in Scala 2.12.6
Original question (for Scala 2.11.7):
Why so strange warning?
scala> null.asInstanceOf[Double]
res0: Double = 0.0
scala> null.asInstanceOf[Double] == null
<console>:11: warning: comparing values of types
Double and Null using `==' will always yield !!!!false!!!!
null.asInstanceOf[Double] == null
^
res1: Boolean = true //!!!!
scala> 0.0 == null
<console>:11: warning: comparing values of types Double and Null using `==' will always yield false
0.0 == null
^
res2: Boolean = false
scala> null.asInstanceOf[Double] == 0.0
res6: Boolean = true
scala> val a = null.asInstanceOf[Double]
a: Double = 0.0
scala> a == null
<console>:12: warning: comparing values of types Double and Null using `==' will always yield false
a == null
^
res7: Boolean = false
P.S. Same for Int
and Long
P.S.2 It's not a duplicate - the problem here is that boxing doesn't happen at all regardless of asInstanceOf
(as you can see from my answer) + the warning message is inconsistent