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

Given the code fragment:

List codes = Arrays.asList (10, 20);

UnaryOperator uo = s -> s +10.0;

codes.replaceAll(uo);

codes.forEach(c -> System.out.println(c));

What is the result?

    Correct Answer: C

    The code will result in a compilation error because the UnaryOperator<Double> uo expects a Double input, but the list codes contains Integer elements. Since Integer and Double are incompatible types, this mismatch will cause a compilation error when trying to apply the UnaryOperator to the list of Integers.

Discussion
M_JawadOption: C

The 12th line of the program will compile error, because the generic type of List is Integer, but UnaryOperator uses Double, which is different, so the compilation error.

thetechOption: C

Answer is C. Tested.

asdfjhfgjuaDCVOption: C

Tested: C is the correct answer

steefaandOption: C

C is answer as Integer cannot be cast to Double.

WilsonKKerllOption: C

Answer is C.