9 Supplier<Map<Integer, String>> s2 = () -> {return new HashMap<>();};
10 System.out.print(s2.get());
11 }}
Choice:
A. program print nothing
B. HashSetHashSetHashMap
C. SetSetMap
D. [][]{}
E. two space followed by {}
F. three empty space
G. code does not compile
H. code compiles but throw runtime exceptions.
Explain: Supplier functional interface takes no parameter, returns an object of the defined type. Line 5 declared a Supplier returns an object of type Set<String>. HashSet<String>::new and () -> new HashSet<String>() are method reference and corresponding lambda function. Line 9 defined a Supplier returns an object of type Map<Integer, String>. Supplier functional interface defined the method get(), which is used to get the object supplied by the supplier. An empty HashSet<String> print a [], an empty HashMap<Integer, String> print a {}.