0
0
Kotlinprogramming~5 mins

This vs it receiver difference in Kotlin - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What does the this keyword refer to in Kotlin lambdas?
<p><code>this</code> refers to the instance of the class where the lambda is defined, not the lambda itself.</p>
Click to reveal answer
beginner
What is the role of it in Kotlin lambdas?

it is the implicit name of the single parameter passed to a lambda when no explicit name is given.

Click to reveal answer
intermediate
How does this differ from it in Kotlin lambda expressions?
<p><code>this</code> refers to the outer class or receiver object, while <code>it</code> refers to the lambda's single input parameter.</p>
Click to reveal answer
beginner
In Kotlin, when do you use it instead of naming the lambda parameter?

When the lambda has exactly one parameter and you don't explicitly name it, Kotlin uses it as the default name.

Click to reveal answer
intermediate
Can this be used inside a lambda to refer to the lambda itself?
<p>No, <code>this</code> always refers to the outer receiver or class instance, not the lambda. To refer to the lambda parameter, use <code>it</code> or name it explicitly.</p>
Click to reveal answer
In a Kotlin lambda with one parameter, what does it represent?
AThe single parameter passed to the lambda
BThe outer class instance
CThe lambda itself
DA keyword to refer to the receiver object
What does this refer to inside a Kotlin lambda expression?
AThe lambda's single parameter
BA local variable inside the lambda
CThe lambda itself
DThe outer class or receiver object
If you want to refer to the lambda's parameter explicitly, what should you do?
AUse <code>it</code> or name the parameter explicitly
BUse <code>self</code>
CUse <code>this</code>
DUse <code>lambda</code>
Which keyword refers to the instance of the class where the lambda is defined?
Ait
Bthis
Cself
Dlambda
When is it NOT available in a Kotlin lambda?
AWhen the lambda has exactly one parameter
BWhen the lambda is inside a class
CWhen the lambda has no parameters
DWhen <code>this</code> is used
Explain the difference between this and it in Kotlin lambdas.
Think about what each keyword points to inside and outside the lambda.
You got /4 concepts.
    When should you use it and when should you use this inside Kotlin lambda expressions?
    Consider the context of the lambda and the class it is in.
    You got /4 concepts.