1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 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:

Show Answer
Correct Answer: BD

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

3 comments
Sign in to comment
PasciOption: B
May 24, 2020

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

iSnoverOption: B
Feb 7, 2024

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

DarGrinOption: B
Jun 7, 2024

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