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,兩者不同所以編譯錯誤。