I'm curious if there might be any subtle differenc...
# announcements
l
I'm curious if there might be any subtle difference between how
y
and
z
are defined, or is it really the same thing?
Copy code
val x: Int? = 0
val y = x!!
val z = x as Int
s
I mean it’s not quite the same thing
x!!
will throw a
NullPointerException
if it’s null
x as Int
will throw a
ClassCastException
l
OK, good point.
d
it will throw
kotlin.TypeCastException
.
and the prior throws
kotlin.KotlinNullPointerException
👍 1