What must be true of a local variable from the enclosing method that is used inside a Java lambda body?
Correct answer B. It must be final or effectively final
Explanation
A lambda may capture a local variable only if that variable is final or effectively final, meaning it is never reassigned after initialisation. The lambda may outlive the method, so it works with a copy of the value, and reassignment would make that copy misleading. Fields do not have this restriction, as they are accessed through objects.
Answer checked How we write and check questions
Discussion