?.let vs if not null

I just found out the difference i was looking for, from this video: 10 Kotlin Tricks in 10 ish minutes by Jake Wharton - YouTube

When i use an if statement with a var, the var can be changed by some other thread in the middle of my if statement, whilst with ?.let {}, the var is read only once and then used inside the let closure, i suppose similarly to the copy method suggested by @Filipp.Riabchun

So as i assume all var variables in kotlin are volatile, the ?.let method is more preferred with them, while with val there is no difference between let and if

3 Likes