Tsallaka zuwa abun ciki
Justice Tech School

Any, is and as

Any is the root type. is tests a type and as casts. Use as? for a safe cast.

Example
val x: Any = "text"
println(x is String)
val s = x as String
println(s.length)
val n = x as? Int
println(n)

Exercise

Safe cast.

x ? Int

Quiz Test

What does as? return on failure?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.