Dear All,
I am reading Generics, below method is confusing. It clearly mentioned in the Method parameter that it should accept only List. But when i give ArrayList as Argument it compiles. It should be only List right? eventhough Arraylist is an implementaion class. below is the code PLease explain.
public class Quiz extends StringCheck {
public Quiz() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Number> input =null;
List<Number> output = null;
output = process(input);
}
static <E extends Number> List<E> process(List<E> nums){
return nums;
}
}
** Here the input argument is arraylist but not List as specified in the method but still it compiles !! but when i change the output to ArrayList opposing the generic type mentioned in the method it throws error **