Java OCA OCP Practice Question 1679

Question

Which of the following lambda expressions can be passed to a method that takes IntFunction<Integer> as an argument?

  • I. (Integer f) -> f
  • II. (v) -> null
  • III. s -> s
  • A. I, II, and III
  • B. II and III only
  • C. III only
  • D. None of the above


B.

Note

To start with, IntFunction<Integer> takes an int value and returns an Integer.

The first statement uses Integer instead of int as the input argument and is therefore not compatible.

The second statement is compatible, since the return type null can be used as an Integer return type.

The last statement is also valid.

An int can be autoboxed to Integer.

For these reasons, Option B is the correct answer.




PreviousNext

Related