Java SE 8 Programmer II — Question 71
Given the code fragment:
List<Double> doubles = Arrays.asList (100.12, 200.32);
DoubleFunction funD = d ""> d + 100.0;
doubles.stream (). forEach (funD); // line n1 doubles.stream(). forEach(e ""> System.out.println(e)); // line n2
What is the result?
Answer options
- A. A compilation error occurs at line n2.
- B. 200.12 300.32
- C. 100.12 200.32
- D. A compilation error occurs at line n1.
Correct answer: A
Explanation
The correct answer is A because the lambda expression used in 'forEach' at line n2 is not properly defined, leading to a compilation error. The other options suggest correct execution or expected outputs, which do not occur due to the error present in the code.