Given a method declared as:
public static <E extends Number> List<? super E> process(List<E> nums)
A programmer wants to use this method like this:
// INSERT DECLARATIONS HERE
output = process(input);
Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)
A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;
B. ArrayList<Integer> input = null;
List<Integer> output = null;
C. ArrayList<Integer> input = null;
List<Number> output = null;
D. List<Number> input = null;
ArrayList<Integer> output = null;
E. List<Number> input = null;
List<Number> output = null;
F. List<Integer> input = null;
List<Integer> output = null;
G. None of the above.
Correct Answer is:
B
E
F
<E extends Number> is defined as type of Method! and the return type is <? super E> so, the output should be of type Number or Object, hoe it is Integer. And Similarly as argument of Type is defined as <E> it should be of Type Number.
So, i was thinking the answer is E. I am really Confused with this Generic typed Class and Methods.
KS&BB describes
Thread as toughest Chapter, but i suppose its the toughest Chapter on Exam!
Thanks,
Shivey