DEV Community

Discussion on: Kotlin safe casting

4gus71n profile image
Agustín Tomas Larghi

Nice! I usually do something like this for getting the extras from the bundle in the onCreate. You can also do something like:

val myFoo = myBar as? Boo ?: RuntimeException("myBar should be Boo")
// myFoo is Boo here. Usually I do things like this when I know for sure that I should have a variable of type Boo. You can do things like this with Context or Bundle values.