Given the code fragment:



UnaryOperator<Integer> uo1 = s -> s * 2; //line n1
List<Double> loanValues = Arrays.asList(1000.0, 2000.0);
loanValues.stream()
        .filter(lv -> lv >= 1500)
        .map(lv -> uo1.apply(lv)) //line n2
        .forEach(s -> System.out.print(s + " "));

What is the result?

A. 4000.0
B. 4000
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.

題解

程式第10行會編譯錯誤,原因在於List的泛型型態為Double,而UnaryOperator卻是使用Integer,兩者不同所以編譯錯誤。