Question 3
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.function.Function;
public class Main {
public static void main(String[] args) {
Function<String, Integer> len = (a, b) -> a.length();
System.out.println(len.apply("java"));
}
}
- A length is not a method
- B Function.apply takes one argument, but the lambda declares two parameters; use a BiFunction or one parameter Correct
- C Function needs three type arguments
- D a must be declared String
Correct Answer: Option B
javac: "incompatible parameter types in lambda expression".
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!