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.
题解
Function 的 JDK 源代码片段如下:
public interface Function<T, R> {
R apply(T t);
}
选项 A,要回传 R 型态的对象才对。
选项 B,要回传 R 型态的对象才对。
选项 C,传入的参数型态不一定要跟回传型态一样。
选项 D,正确。
