for example:
v1?.apply {
v2?.apply {
call(this, target, outerThis);
}
}
my question is how to refer to "outerThis"? thanks for any help.
Hence, they can be included into call chains as side steps: you can continue chaining function calls on the same object after them. They also can be used in return statements of functions returning the context object.
:: is just a way to write a lambda expression basically we can use this to refer to a method i.e a member function or property for example class Person (val name: String, val age: Int) Now we can write this to access the person which has the maximium age.
In Kotlin, the “this” keyword allows us to refer to the instance of a class whose function we happen to be running.
Kotlin apply is an extension function on a type. It runs on the object reference (also known as receiver) into the expression and returns the object reference on completion.
You can use a label and then a qualified this
expression:
v1?.apply outer@ {
v2?.apply {
call(this, target, this@outer)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With