Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction
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:
Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction
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:
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.
B is correct: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y;
Answer is B. IntStream.map() takes an IntUnaryOperator
B is correct: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y;