Java OCA OCP Practice Question 2777

Question

Which of the following is equivalent to this code?

UnaryOperator<Integer> u = x -> x * x; 
  • A. BiFunction<Integer> f = x -> x*x;
  • B. BiFunction<Integer, Integer> f = x -> x*x;
  • C. BinaryOperator<Integer, Integer> f = x -> x*x;
  • D. Function<Integer> f = x -> x*x;
  • E. Function<Integer, Integer> f = x -> x*x;
  • F. None of the above


E.

Note

A UnaryOperator is a special type of function where the parameter and return type are the same.

Therefore, option E is correct.

Notice that other options don't even compile because they have the wrong number of generic types for the functional interface provided.




PreviousNext

Related