Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 159

Given:

Which is true?

    Correct Answer: B

    The code does not compile because lambda expressions in Java can only capture variables that are final or effectively final. In this code, the variable 'i' is modified by the 'i++' statement after it is assigned to the lambda expression, making it no longer effectively final. As a result, this causes a compilation error.

Discussion
d7bb0b2Option: B

variables in lamba must be effectively final or final, whhen i is modified i++, compilation error is show.

OmnisumemOption: B

error: local variables referenced from a lambda expression must be final or effectively final

StavokOption: B

B is correct

KiraguJohnOption: B

Answer is B. lambda expressions work with final variables, as well as effectively final variables. The moment you do something like i++ the variable i will be no longer treated as final