Question 2
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
public static void main(String[] args) {
Object task = () -> System.out.println("hi");
System.out.println(task);
}
}
- A println cannot print lambdas
- B A lambda needs a functional-interface target type; Object is not one – use Runnable task = … Correct
- C Lambdas cannot print
- D task must be final
Correct Answer: Option B
javac: "incompatible types: Object is not a functional interface". (Object o = (Runnable) () -> … would compile.)
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!