I stumbled upon a question(in McGraw-Hill/Osborne - Katty Sierra).
Chapter 7 , Questions 16.
I did a copy and paste but it does not compiles and the worst, the given anwser seems not to be correct.
Can you help me ? Thanks.
16. 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.
Here is what i did :
public class
Test {
public static <E extends Number> List<? super E> process(List<E> nums){
return nums;
}
public static void main(
String[] args) {
// INSERT DECLARATIONS HERE
ArrayList<Integer> input1 = new ArrayList<Integer>();
ArrayList List<Integer> output = process(input1);
ArrayList<Integer> input2 = new ArrayList<Integer>();
List<? super Number> output2 = process(input2);
ArrayList<Integer> input3 = new ArrayList<Integer>();
List<? super Number> output3 = process(input3);
List<Number> input4 = null;
ArrayList<Integer> output4 = process(input4);
List<Number> input5 = null;
List<Number> output5= process(input5);
List<Integer> input6 = null;
List<Integer> output6 = process(input6);
}
}