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

Given the code fragment:

BiFunction val = (t1, t2) -> t1 + t2; //line n1

//line n2

System.out.println(val.apply(10, 10.5));

What is the result?

    Correct Answer: C

    The code does not compile because the lambda expression's return type is expected to be an Integer as specified by the BiFunction<Integer, Double, Integer>. However, adding an Integer and a Double results in a Double, which cannot be directly assigned to the expected Integer return type without explicit casting, leading to a compilation error at line n1.

Discussion
jduarteOption: C

answer C. If line n1 looks like below, A is the correct answer. BiFunction val = (t1, t2) -> t1 + t2; //line n1

AVB22

if it is like that you will have following error: The operator + is undefined for the argument type(s) java.lang.Object, java.lang.Object

fffffOption: C

Bad return type in lambda expression: double cannot be converted to Integer in line n1 so answer C

WilsonKKerllOption: C

Answer is c.

asdfjhfgjuaDCVOption: C

C is the correct answer

steefaandOption: C

C is correct. Double can't be cast to Integer.

iSnoverOption: C

Answer is C, Bad return type in lambda expression: double cannot be converted to Integer.

grigladOption: C

Autounboxing is needed for the values to be added. The main point here is when we add a double to an int , double is returned . So if we had BiFunction<Integer,Double,Double> it would compile file. The answer is C