Java SE 8 Programmer II — Question 105

Given the code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2; //line n1
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?

Answer options

Correct answer: D

Explanation

The correct answer is D because the BiFunction is defined to take an Integer and a Double, but the lambda expression attempts to add them directly, which leads to a type mismatch. Line n1 does not cause a compilation error, and thus the other options are incorrect.