Hi! Everyone,
I have a doubt in getting through question no 16. from K&B (page 634)
Given a method as
public static <E extends Number> List<? super E> process(List<E> nums)
A programmer want to use this method like this
// INSERT DECLARATIONS HERE
output=process(input);
which pair of declarations could be placed at //INSERT DECLARATION HERE to allow the code to compile.
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 these
Correct answers are: B,E and F
I have doubt related to C
ArrayList <Integer> input=null
List <Number> output=null As the return type in the method declaration states
public static <E extends Number>
List<? super E> process(List<E> nums) that means we can have super class of the value for E as generic type of List as return value.
so if i have ArrayList <Integer> input ,so corresponding to Integer for place holder E why can't i have List <Number > output as return value.
Please clarify in detail as i am not able to get the reason.
Regards
Jolly