Java OCA OCP Practice Question 1531

Question

Which of the following is not a valid lambda expression?

  • A. (Integer j, k) -> 5
  • B. (p,q) -> p+q
  • C. (Integer x, Integer y) -> x*y
  • D. (left,right) -> {return "null";}


A.

Note

Option A is the invalid lambda expression because the type is specified for the variable j, but not the variable k.

The rest of the options are valid lambda expressions.

To be a valid lambda expression, the type must be specified for all of the variables, as in Option C, or none of them, as in Options B and D.




PreviousNext

Related