Ivan Brko
09/11/2021, 10:40 AMwhen
, so that i could write something like this:
when (expression generating nullable){
null -> handle null
x -> handle x for which compiler knows its not null anymore
}
Joffrey
09/11/2021, 10:41 AMJoffrey
09/11/2021, 10:43 AMx
you can do so inside the `when`:
when(val x = expression)
Ivan Brko
09/11/2021, 10:43 AMwbertan
09/11/2021, 10:43 AMfun maybe(): String? = null
fun asas() {
when (val maybe = maybe()){
null -> println("it was null!")
"something" -> println("maybe is something! Check: $maybe")
else -> println("I don't know what it is! Check: $maybe")
}
}
Ivan Brko
09/11/2021, 10:44 AM