Given the code fragments:
andWhat is the result?
Given the code fragments:
andWhat is the result?
The code will result in a compilation error. The method printValues() in the class Test does not take any arguments, yet it is being referenced in the context of forEach, which requires a Consumer function that accepts a String argument. Additionally, printValues() is not a static method, but the forEach call attempts to use method references that would necessitate either a static method or an instance method that matches the expected signature.
Answer B. Tested . t.getList().forEach(Test::printValues) Multiple markers at this line - The type Test does not define printValues(String) that is applicable here - The method forEach(Consumer<? super String>) in the type Iterable<String> is not applicable for the arguments (Test1::printValues)
B- compilation error. printvalues must be static
true B
Answer B. Method printValues() should take a String and be public like this: public static void printValues(String s) {System.out.println(s);}
Sorry, and be static
B is correct.
Actual answer is B because the method should be static