Java SE 8 Programmer II — Question 47

Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction<Integer> inFu= x -> y -> x*y; //line n1
IntStream newStream = stream.map(inFu.apply(10)); //line n2 newStream.forEach(System.output::print);
Which modification enables the code fragment to compile?
line n1 with:

Answer options

Correct answer: D

Explanation

The correct answer is D because the current type used in the lambda does not match the expected functional interface for the IntStream map operation. The other options suggest changes that do not resolve the type mismatch or are not applicable to the context of the code.