What is the result of the following code?
public interface Checker { boolean check(int height, int limit); } public class Main { public static void main(String[] args) { check((h, l) -> h.toString(), 5); // x1 } /*from ww w .j a v a 2s.co m*/ private static void check(Checker check, int height) { if (check.check(height, 10)) // x2 System.out.println("too high"); else System.out.println("ok"); } }
C.
The functional interface takes two int parameters.
The code on line x1 attempts to use them as if one is an Object, resulting in a compiler error making C the correct answer.
It also tries to return String even though the data type for the functional interface method is boolean.
It is tricky to use types in a lambda when they are implicitly specified.
Remember to check the interface for the real type.