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?