with
function
with
is a useful function included in the standard Kotlin library. It basically receives an
object and an extension function as parameters, and makes the object execute the function.
This means that all the code we define inside the brackets acts as an extension function
of the object we specify in the first parameter, and we can use all its public functions and
properties, as well as
this
. Really helpful to simplify code when we do several operations
over the same object.
There’s a lot of new code in this chapter, so feel free to check it out on the
repository¹⁸
.
¹⁸
https://github.com/antoniolg/Kotlin-for-Android-Developers
Do'stlaringiz bilan baham: |