Given the code fragment:
BiFunction
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?
Given the code fragment:
BiFunction
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?
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.
answer C. If line n1 looks like below, A is the correct answer. BiFunction val = (t1, t2) -> t1 + t2; //line n1
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
Bad return type in lambda expression: double cannot be converted to Integer in line n1 so answer C
Answer is c.
C is the correct answer
C is correct. Double can't be cast to Integer.
Answer is C, Bad return type in lambda expression: double cannot be converted to Integer.
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