Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
A compilation error occurs at line n2 because the predicate 'test2' is not correctly parameterized. Predicate in Java generics should have a type parameter specified, such as Predicate<String>. Without this parameter, the compiler expects an Object type, leading to a compilation error.
answer is D. tested. compiler error is "lambda parameter is expected of type Object"
Answer is D public class Test { public static void main (String[] args) throws InterruptedException { List<String> words = Arrays.asList("win", "try", "best", "luck", "do"); Predicate<String> test1 = w -> { System.out.println("Checking..."); return w.equals("do"); }; Predicate test2 = (String w) -> w.length() > 3; words.stream() .filter(test2) .filter(test1) .count(); } }
answer is D
Predicate<String> test2 = (String str) -> str.length() > 3; // line n2
answer is D
The correct answer is C the instructionPredicate<String> test1=w->{System.out.println(""); is ok
D is the correct answer
Answer is D since Predicate is not parametrized and expects Object as input.
D is correct, Predicate<T> need a type parameter.
Predicate is not parameterized so it is using raw type. Compilation error at line n2. Answer is D
The answer is C
D, tested
D,tested