Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 174

Given:

Which action will enable the code to compile?

    Correct Answer: C

    To ensure the code compiles, we need to correctly match the types expected by the `IntStream.map` method. This method accepts an `IntUnaryOperator`, which is a functional interface representing an operation on a single `int` operand that produces an `int` result. The line `IntFunction<IntUnaryOperator> func = x -> y -> x * y;` correctly defines a function `func` that takes an `int` and returns an `IntUnaryOperator`. This operator effectively multiplies the given operand by `x`, where `x` is specified when invoking `func.apply(10)`. Therefore, option C is the correct choice.

Discussion
ASPushkinOption: C

answer : looks like C and D(same) "func" should have input : int and output: IntUnaryOperator Correct answer : IntFunction<IntUnaryOperator> func = x->y->x*y; IntUnaryOperator oper = y->x*y; where x and y are type of int by definition

KiraguJohn

What is the difference between C and D?

d7bb0b2Option: C

NO ANSWER CORRECT THE ONLY wait to this is ok is: IntFunction<IntUnaryOperator> func = x -> y -> x * y; then instream.map(func.apply(...)).....

d7bb0b2

Instream.map() method only aceppt IntUnaryOperator not IntFunction

ASPushkin

B) is not right 1) Function is raw type 2) func.apply(10) has just one input parameter

ASPushkin

IntFunction is a raw type and it equals to IntFunction<Object> so right answer is IntFunction<IntUnaryOperator> func = x-> y->x*y;

[Removed]

There's so much missing in this question it's almost impossible to even try to solve this. ALSO C & D are the exact same.

[Removed]

It's definitely not A as the BiFunction's apply method takes 2 parameters. I'm guessing the correct answer has to be something like this IntFunction<IntFunction<Integer>>

d7bb0b2

IntFunction<IntFunction<Integer>> can not resolve the problem because map of Instream only aceppt IntUnaryOperator not IntFunction