Please, consider the Test
Java class below.
Why does test2()
method compile successfully, but test1()
doesn't?
import java.util.Arrays;
import java.util.List;
public class Test {
public <N extends Number> List<N> test1(){
//compile error: Type mismatch: cannot convert from List<Integer> to List<N>
return Arrays.asList(1,2,3);
}
public List<? extends Number> test2(){
//no compile error
return Arrays.asList(1,2,3);
}
}