Choose the correct option based on this program:.
import java.util.function.Predicate; public class Main { public static void main(String []args) { Predicate<String> notNull = ((Predicate<String>)(arg -> arg == null)).negate(); // #1 System.out.println(notNull.test(null)); } }
C.
the expression ((Predicate<String>)(arg -> arg == null)) is a valid cast to the type (Predicate<String>) for the lambda expression (arg -> arg == null).
hence, it does not result in a compiler error.
the negate function in Predicate interface turns true to false and false to true.
hence, given null, the notNull
.
test(null) results in returning the value false.