Let

The Let function also extends the generic T type parameter, but it accepts a normal function as an argument and returns the result of that function. It can be used to do something with an object and then return a different value:

val str: String = StringBuilder().let { sb ->
sb.appendln("First Line")
sb.appendln("Second Line")
sb.appendln("Third Line")
sb.toString()
}

The lambda passed to let will get one argument, and that is the instance from which the let function was called. In this case, the sb argument is the StringBuilder instance from which we called the let function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.68.159