Thank you for the response. I’m not sure if I am understanding exactly what you are saying though.
That looks like a good example of the usage of “this”.
But I’m still not fully understanding what a receiver is.
I have continued to read sources, blogs, forums, code examples etc to try to understand better, and I do feel like I’m getting a better grasp.
From what I understand, a receiver is simply some object that has an extended function called on it, right? Nothing more complicated than that?
Now when it comes to “this” vs “it”: these are just shortcut keywords. “This” is used to refer to the object or “receiver” that an extended function is called on, while “it” is used to refer to a parameter being passed in a lambda/anonymous function. Do I have that right?
They clearly refer to different things, but both are still shortcuts available to make code more concise. I’m assuming that “this” and “it” can NOT be used in the same block of code, is that correct? For example, with Kotlin’s standard functions, like Let, “this” isn’t available because the scope is on the receiver as a parameter, not an object, whereas “it” can be used to refer to the parameter which is the receiver itself. But for functions like apply and run, “this” can be used because the receiver isn’t being passed into the lambda as a parameter, but they are acting on the receiver as an object, whereas “it” can’t be used because there is no parameter scoped in the apply or run function call.
Am I getting it?