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
Casting a numeric value type to another will result in a conversion:
5L.asInstanceOf[Int] // --> 5: Int
(5L:Any).asInstanceOf[Int] // throws ClassCastException
Boxing should be transparent, so they should result in the same behavior.
It is discussable which behavior is desirable:
From a typing point of view, a Long is not an Int and the cast should therefore fail. Also, a cast could/should be considered as a pure type operation and not a conversion/coercion.
The scala spec supports the behavior of the unboxed version in §12.1
The text was updated successfully, but these errors were encountered:
Casting a numeric value type to another will result in a conversion:
Boxing should be transparent, so they should result in the same behavior.
It is discussable which behavior is desirable:
Long
is not anInt
and the cast should therefore fail. Also, a cast could/should be considered as a pure type operation and not a conversion/coercion.The text was updated successfully, but these errors were encountered: