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?✗ Incorrect
it is the implicit name for the single parameter of a lambda when no explicit name is given.
What does
this refer to inside a Kotlin lambda expression?✗ Incorrect
this refers to the outer class or receiver object, not the lambda parameter.
If you want to refer to the lambda's parameter explicitly, what should you do?
✗ Incorrect
You can use it if the lambda has one parameter and no explicit name, or you can name the parameter explicitly.
Which keyword refers to the instance of the class where the lambda is defined?
✗ Incorrect
this refers to the instance of the class or the receiver object where the lambda is defined.
When is
it NOT available in a Kotlin lambda?✗ Incorrect
it is only available when the lambda has exactly one parameter and no explicit name is given.
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.