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 ]
for the above method declaration: No. since the output is ArrayList while it s/b List. Yes No, since the output is Number while it s/b something that extends Integer. No, same reason as A Yes, <Number extends Number> for both input and output. Yes [ September 19, 2006: Message edited by: M Krishnan ]
Try placing the option A above the line 'output = process(input)' (as given above). You're actually assigning 'output' (which is of type ArrayList) with the value returned from the method (which is of type List ).
You can assign an ArrayList to a List and not the other way around. (ArrayList 'is a' List but not the other way ). [ September 20, 2006: Message edited by: M Krishnan ]
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad: