https://kotlinlang.org logo
#announcements
Title
# announcements
r

robin

02/22/2017, 12:05 PM
So you don't have a noop. This is basically the same as doing:
Copy code
val unwrapped = optional
if(unwrapped != null) { doSmth() }
else { doSmthElse() }
m

mg6maciej

02/22/2017, 12:09 PM
robin: I like this version more!
r

robin

02/22/2017, 12:10 PM
Yeah me too, actually... The elvis operator can make stuff obscure at times.
The
?.let
notation is only preferrable to an old-fashioned null check if the variable in question is non-local so you need an immutable local copy and you don't need an else-branch, imo.
a

Andreas Sinz

02/22/2017, 12:26 PM
@robin it is not the same. if
doSometh()
returns null,
doSmthElse()
will be called too
r

robin

02/22/2017, 12:28 PM
@Andreas Sinz You're correct. I was implying that doSometh() was just of Unit return type and therefore couldn't return null. If that's not the case you have to get around that.