Which statements about the following application are true?
1: package mypkg; 2: import java.util.function.*; 3: class Shape {} 4: public class Main { 5: public class Car { 6: int count; 7: public final Function<Shape,Main,Car> f = (h,w) -> new Car(); 8: public final IntSupplier<Integer> add = () -> count++; 9: } /*w ww .j a va 2 s.c om*/ 10: public static void main(String[] knight) { 11: final Car a = new Car(); 12: a.f.apply(new Shape(), new Main()); 13: a.add.getAsInt(); 14: } 15: }
E.
The first statement is not true because Function takes two generic arguments and one input argument.
If BiFunction was used instead of Function on line 7, then the code would compile correctly.
The second statement is also not true because IntSupplier does not take any generic arguments.
The third statement is not true as well, since Car is an inner instance class.
Without an instance of Main in the static main()
method, the call new Car()
on line 11 does not compile.
For these reasons, all three statements are not true, making Option E the correct answer.