What is true about the following?
import java.util.*; public class Main { public static void main(String[] args) { List list = Arrays.asList("Main"); method(list); // c1 } /*from ww w. j a va 2s. c o m*/ private static void method(Collection<?> x) { //c2 x.forEach(a -> {}); // c3 } }
D.
This code actually does compile.
Line c1 is fine because the method uses the ? wildcard, which allows any collection.
Line c2 is a standard method declaration.
Line c3 looks odd, but it does work.
The lambda takes one parameter and does nothing with it.
Since there is no output, Option D is correct.