Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.function.Predicate;
public class Main {
public static void main(String[] args) {
Predicate<String> longWord = s -> s.length();
System.out.println(longWord.test("generics"));
}
}
- A test is not a method
- B Predicate.test must return boolean, but s.length() is an int; write s -> s.length() > 5 Correct
- C Predicate needs two type arguments
- D s must be declared
Correct Answer: Option B
javac: "bad return type in lambda expression: int cannot be converted to boolean".
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!