Which of the following lines can be inserted at line 11 to print true?
Choose all that apply
10: public static void main(String[] args) { 11: // INSERT CODE HERE 12: } 13: private static boolean test(Predicate<Integer> p) { 14: return p.test(5); 15: }
A, C, F.
The only functional programming interface you need to memorize for the exam is Predicate.
It takes a single parameter and returns a boolean.
Lambda expressions with one parameter are allowed to omit the parentheses around the parameter list, making options A and C correct.
The return statement is optional when a single statement is in the body, making option F correct.
Option B is incorrect because a return statement must be used if braces are included around the body.
Options D and E are incorrect because the type is Integer in the predicate and int in the lambda.
Autoboxing works for collections not inferring predicates.
If these two were changed to Integer, they would be correct.