https://kotlinlang.org logo
Title
o

ontherunvaro

12/20/2017, 9:49 AM
Is it better to use
variable?.let{...}
or
if (variable != null) {...}
?
g

groostav

12/20/2017, 9:50 AM
if
variable
is a local stack variable, I'd go with option 2 since its brain dead. If
variable
is a field, option 1 is more elegant
o

ontherunvaro

12/20/2017, 9:51 AM
sorry, I don't understand what "brain dead" means in this context
care to explain?
g

groostav

12/20/2017, 10:46 AM
any programmer from a C-like language is going to know what
if(x != null){ doStuff(x) }
means
?.let {
is simply a kotlin-specific thing, ergo you need to be more comfortable with the language to understand it
👍 1