if I want to check a nullable Boolean
I get a type mismatch
var bool: Boolean? = true
if(bool)
println("foo")
else
println("bar")
because Boolean is expected
not Boolean?
If you want to treat null
case differently from either true
or false
:
when(bool) {
null -> println("null")
true -> println("foo")
false -> println("bar")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With