Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 209

Given:

IntStream stream = IntStream.of (1,2,3);

IntFunction 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:

    Correct Answer: B

    To make the code fragment compile, the IntFunction should be replaced with IntFunction<IntUnaryOperator>. This is because the map function in IntStream expects an IntUnaryOperator which applies to a single integer and returns a single integer. The replacement allows the lambda expression x -> y -> x * y to fit the expected type.

Discussion
PasciOption: B

B is correct: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y;

DarGrinOption: B

Answer is B. IntStream.map() takes an IntUnaryOperator

iSnoverOption: B

B is correct: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y;