gildor
03/06/2018, 7:49 AMval unwrapped = foo?.something
if (unwrapped != null) {
unwrapped.soSomething()
} else {
otherStuff()
}
But you need this only when smartcast doesn’t work for you
Also you can do something like this:
val unwrapped = foo?.something ?: return otherStuff()
// or just
val unwrapped = foo?.something ?: return
// or throw error
val unwrapped = foo?.something ?: error("foo is null")
// and now you can use unwrapped as non-null
unwrapped.soSomething()