OCP Question 39, Explanation

Which statement is true about the single abstract method of the java.util.function.Function interface?

A. It accepts one argument and returns void.
B. It accepts one argument and returns boolean.
C. It accepts one argument and always produces a result of the same type as the argument.
D. It accepts an argument and produces a result of any data type.

 

The correct answer is D.

 

We’ve already touched upon something closely related to this question when discussing Problem 33. The functional method apply() in Function accepts a single arg and returns a value whose type can be any.  UnaryOperator, which returns a value of the same type, is the only direct subinterface of Function, and in cases that deal with two args, we can use BiFunction and BinaryOperator.

Leave Comment

Your email address will not be published. Required fields are marked *