Which functional interface, when filled into the blank, allows the class to compile?
package mypkg;//from ww w.j a v a2 s. com import java.util.function.*; public class Main { public void mine(____ lambda) { // TODO: Apply functional interface } public static void main(String[] debris) { new Main().mine((s,p) -> s+p); } }
B.
The lambda (s,p) -> s+p takes two arguments and returns a value.
Option A is incorrect because BiConsumer does not return any values.
Option D is also incorrect, since Function only takes one argument and returns a value.
Options B and C both use BiFunction, which takes two generic arguments and returns a generic value.
Option C is incorrect because the datatype of the unboxed sum s+q is int and int cannot be autoboxed or implicitly cast to Double.
Option B is correct.
The sum s+p is of type double, and double can be autoboxed to Double.