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;
my comments: E replaced by Integer and ? replaced by Integer,
which meets the return collection type bound <Integer super Integer>
and the generic declaration <Integer extend Number>.
ArrayList<Integer> should be campatible with List<Integer>
so this is a correct answer.
B. ArrayList<Integer> input = null;
List<Integer> output = null;
my comments: same reasoning as A, this is a correct answer.
C. ArrayList<Integer> input = null;
List<Number> output = null;
my comments: E replaced by Integer and ? replaced by Number,
which meets the return collection type bound <Number super Integer>
and the generic declaration <Integer extends Number>.
so this is a correct answer.
D. List<Number> input = null;
ArrayList<Integer> output = null;
my comments: E replaced by Number and ? replaced by Integer,
which violates because Integer is not a super of Number.
E. List<Number> input = null;
List<Number> output = null;
my comments: E replaced by Number and ? replaced by Number,
which meets the return collection type bound <Number super Number>
and the generic declaration <Number extends Number>.
so this is a correct answer.
F. List<Integer> input = null;
List<Integer> output = null;
my comments: E replaced by Integer and ? replaced by Integer,
which meets the return collection type bound <Integer super Integer>
and the generic declaration <Integer extends Number>.
so this is a correct answer.
So my answer would be: ABCEF.
Is this correct?
[ September 18, 2006: Message edited by: Jacky Zhang ]