yea i do get when you assign to a property, or whe...
# getting-started
u
yea i do get when you assign to a property, or when you need a expression, but other than that im not sold on it, "?.let { }" why not just if != null
a
it allows you to scope something to a specific code block
u
well any { } is a block with its own local vars
oh its not in kotlin, i see
s
When you have a variable that is shared across threads,
if (x != null) x.doSmth()
is not safe, as x could've changed to null in the meantime.
let
uses a temporary to guarantee that it is not affected by other threads.
u
yes ive been just shown that, thank you, so its equivalent to val y = this.x if (y != null) y.doSmth() right?
a
yes
u
I knew that, but didnt realize it, thanks a lot
a
let { }
doesn't replace
if
, just use either one of them when its feasible
u
yea for vals properties its whatever, for vars its useful, thnx