You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the specification, section 6.3 (page 75 of the May 24, 2011 draft) it says:
The null value is of type scala.Null, and is thus compatible with every reference type. It denotes a reference value which refers to a special "null" object. This object implements methods in class scala.AnyRef as follows:
...
asInstanceOf[T] returns the "null" object itself if T conforms to scala.AnyRef, and throws a NullPointerException otherwise.
Yet null.asInstanceOf[Int\] returns 0 instead of throwing an exception. Either the compiler is wrong or the spec needs to be updated.
In the specification, section 6.3 (page 75 of the May 24, 2011 draft) it says:
The null value is of type scala.Null, and is thus compatible with every reference type. It denotes a reference value which refers to a special "null" object. This object implements methods in class scala.AnyRef as follows:
Yet
null.asInstanceOf[Int\]
returns0
instead of throwing an exception. Either the compiler is wrong or the spec needs to be updated.This was found by 爱国者 on http://stackoverflow.com/questions/8285916/why-doesnt-null-asinstanceofint-throw-a-nullpointerexception
The text was updated successfully, but these errors were encountered: