Java OCA OCP Practice Question 725

Question

Which equivalent code can replace i -> i != 0 in the following line?

Predicate<Integer> ip = i -> i != 0; 
  • A. i -> { i != 0 }
  • B. i -> { i != 0; }
  • C. i -> { return i != 0 }
  • D. i -> { return i != 0; }


D.

Note

When you're using brackets, both the return keyword and semicolon are needed for the lambda to compile, making Option D correct.




PreviousNext

Related