Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.function.BiFunction;
public class Main {
public static void main(String[] args) {
BiFunction<Integer, Integer, Integer> add = (var a, Integer b) -> a + b;
System.out.println(add.apply(2, 3));
}
}
- A var cannot hold Integers
- B All lambda parameters must use the same style – all implicit, all var or all explicit types Correct
- C BiFunction needs four types
- D The body needs braces
Correct Answer: Option B
javac: "invalid lambda parameter declaration (cannot mix 'var' and explicitly-typed parameters)".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!