Which lambda expression can be passed to the magic()
method?
package show; import java.util.function.*; public class Main { public void magic(BinaryOperator<Long> lambda) { lambda.apply(3L, 7L); } }
intValue()
)B.
BinaryOperator<Long> takes two Long arguments and returns a Long value.
For this reason, Option A, which takes one argument, and Option D, which takes two Integer values that do not inherit from Long, are both incorrect.
Option C is incorrect because the local variable c is redeclared inside the lambda expression, causing the expression to fail to compile.
The correct answer is Option B because intValue()
can be called on a Long object.
The result can then be cast to long, which is autoboxed to Long.