爲什麼這麼奇怪的警告?不一致的空等式檢查scala 2.11.7
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.同爲Int
和Long
PS2這不是一個重複的 - 這裏的問題是,拳擊不會發生根本不管asInstanceOf
(你可以從我的回答看)+警告信息不一致
HTTP:/ /stackoverflow.com/questions/10749010/if-an-int-cant-be-null-what-does-null-asinstanceofint-mean –
雖然我無法找到規範中明確表示同意的任何內容回答。 –