Given the code fragment:

List<Integer> codes = Arrays.asList(10, 20);
UnaryOperator<Double> uo = s -> s + 10.0;
codes.replaceAll(uo);
codes.forEach(c -> System.out.println(c));

What is the result?

A.

20.0
30.0

B.

10
20

C. A compilation error occurs.
D. A NumberFormatException is thrown at run time.

题解

程序第 12 行会编译错误,原因在于 List 的泛型型态为 Integer,而 UnaryOperator 却是使用 Double,两者不同所以编译错误。