Possible Duplicate:
If an Int can't be null, what does null.asInstanceOf[Int] mean?
I tried the following in REPL:
scala> null.asInstanceOf[Int] res12: Int = 0 scala> null.asInstanceOf[Float] res13: Float = 0.0 scala> null.asInstanceOf[Double] res14: Double = 0.0
It would expect a runtime exception (NPE or ClassCastException) in that case.
Could anybody explain why Scala casts null to zero?
It’s really strange, as it is not the behaviour expected according to the specification:
And it’s a known bug that is closed but related to this one, which is open.