I see a lot of new Kotlin programmers think that `...
# getting-started
p
I see a lot of new Kotlin programmers think that
?.let { ... } ?: ...
is exactly equivalent to
if (not null) ... else ...
but that's just not true in a general case.
1
k
I think this is a super-important distinction to make and why I avoid this construct. Both "branches" will run if your
let { ... }
lambda's last line is an expression that returns
null
. If you start to alias
?.let-?:
to
if-else
in your mind, you're going to be very surprised the first time this happens to you