1Z0-809 practice question 23 of 25

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

Full set: 196 questions
Answer options
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. Correct answer
Correct Answer:
D. It accepts an argument and produces a result of any data type.
Explanation

The java.util.function.Function interface is a generic functional interface. Its single abstract method is R apply(T t). This method takes one argument of generic type T and produces a result of generic type R. The types T and R can be different, allowing the function to transform an object of one type into an object of any other data type. For example, a Function could take a String and return its length as an Integer.

Why Incorrect

A. A functional interface that accepts one argument and returns void is a Consumer.
B. A functional interface that accepts one argument and returns a boolean is a Predicate.
C. A function that accepts and returns the same type is a UnaryOperator, which is a specific sub-interface of Function.

References

- Oracle, Java SE 8 Documentation, java.util.function.Function. The official API documentation specifies the abstract method as R apply(T t).

- Oracle, The Java™ Tutorials, "Standard Functional Interfaces". This tutorial describes the purpose and signature of the Function interface and contrasts it with other interfaces like Predicate and Consumer.

Scroll to Top