kevinmost
05/26/2016, 1:28 PMlet
is useful if you don't want to define a variable and just use it within the scope of the block you're passing to let
. Example:
Normally you'd do:
val foo = lookupFoo()
if (foo != null) {
foo.doThing()
}
It's cleaner to do lookupFoo()?.let { it.doThing() }
No variable needed to be defined