← Quiz: Lambdas and Functional Interfaces: all 10 questions
Quiz: Lambdas and Functional Interfaces · Question 9 of 10
Why must local variables used inside a lambda be effectively final?
Why must local variables used inside a lambda be effectively final?
- A.Because lambdas cannot read variables
- B.Because final variables are faster
- C.The lambda gets a copy of the value and may run later, so the value must not change
- D.Because lambdas run on a separate thread every time
Answer & explanation
Correct answer: The lambda gets a copy of the value and may run later, so the value must not change
Java captures the value, not the variable; allowing changes would make the copy and the original disagree.
Can you get the rest right without peeking?
Take the timed Quiz: Lambdas and Functional Interfaces quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →