Java OCA OCP Practice Question 1498

Question

Which of the following is required for all valid lambda expressions?

  • A. ()
  • B. ->
  • C. {}
  • D. Parameter data type(s)


B.

Note

The lambda expression s -> true is valid, making Options A, C, and D incorrect.

Parentheses () are not required on the left-hand side if there is only one variable.

Brackets {} are not required if the right-hand side is a single expression.

Parameter data types are only required if the data type for at least one parameter is specified, otherwise none are required.

The remaining choice, the arrow operator ->, is required for all lambda expressions, making Option B the correct answer.




PreviousNext

Related