ilya.gorbunov
05/13/2017, 8:29 PMif ((val localVal = nullableExpr) != null && localVal.property = "x") { do something with localVal }
?benleggiero
05/13/2017, 8:37 PMguard
val localVal = nullableExpr
&& localVal.property == "x"
else {
println("nullableExpr was null")
// localVal is nonexistant in this context
return
}
// localVal is guaranteed in this context
doSomething(with = localVal)
or:
if
val localVal = nullableExpr
&& localVal.property == "x" {
// localVal is guaranteed in this context
doSomething(with = localVal)
} else {
// localVal is nonexistant in this context
println("nullableExpr was null")
}
// localVal is nonexistant in this context