Kotlin - Null Safety
What will be the output of this Kotlin code?
val obj: Any = 123 val str: String? = obj as? String println(str)
What will be the output of this Kotlin code?
val obj: Any = 123 val str: String? = obj as? String println(str)
obj holds an integer 123, but we try to cast it to String using safe cast as?.obj is not a String, the safe cast returns null instead of throwing an error.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions