https://kotlinlang.org logo
r

rootandy

02/16/2018, 3:02 PM
but i think you meant the following problem:
Copy code
val foo: String? = null

val bar = foo?.let { thingThatCouldReturnNull() } ?: "Hello"
val baz = if (foo != null) thingThatCouldReturnNull() else "Hello"

println(bar) // prints "Hello" if thingThatCouldReturnNull() returns null
println(baz) // prints "null" if thingThatCouldReturnNull() returns null