Recall & Review
beginner
What is the trailing lambda convention in Kotlin?
It is a Kotlin syntax feature that allows you to pass a lambda expression outside the parentheses of a function call if the lambda is the last argument.
Click to reveal answer
beginner
How do you call a function with a trailing lambda in Kotlin?
You write the lambda expression after the function call parentheses instead of inside them, making the code cleaner and more readable.
Click to reveal answer
beginner
Example: Convert this call to use trailing lambda:
list.filter({ it > 5 })list.filter { it > 5 } The lambda is moved outside the parentheses because it is the last argument.Click to reveal answer
intermediate
Can you use trailing lambda if the lambda is not the last argument?
No, trailing lambda syntax only works if the lambda is the last argument in the function call.
Click to reveal answer
beginner
Why is trailing lambda convention useful?
It makes code easier to read and write, especially when lambdas are long or nested, by reducing parentheses clutter.
Click to reveal answer
What does the trailing lambda convention allow in Kotlin?
✗ Incorrect
Trailing lambda lets you put the lambda outside the parentheses when it is the last argument.
Which of these is a correct use of trailing lambda?
✗ Incorrect
Option A uses trailing lambda syntax correctly by placing the lambda outside parentheses.
Can you use trailing lambda if the function has multiple arguments and the lambda is not last?
✗ Incorrect
Trailing lambda works only when the lambda is the last argument.
What is a benefit of using trailing lambda?
✗ Incorrect
Trailing lambda improves readability by reducing parentheses clutter.
Which Kotlin feature is demonstrated by this code?
button.setOnClickListener { println("Clicked") }✗ Incorrect
The lambda passed outside parentheses shows trailing lambda convention.
Explain the trailing lambda convention in Kotlin and when you can use it.
Think about how lambdas are passed to functions.
You got /3 concepts.
Give an example of a function call using trailing lambda and explain why it is valid.
Try using list.filter or similar function.
You got /3 concepts.