I want to convert array to list, but when I explicitly specify the type of the list in Integer, the build fails:
int[] nums = {1, 2 ,3};
List<Integer> test1 = Arrays.asList(nums);
The error is:
error: incompatible types: inference variable T has incompatible bounds List test1 = Arrays.asList(nums); ^ equality constraints: Integer lower bounds: int[] where T is a type-variable: T extends Object declared in method asList(T...)
However, after I removed the type information every works fine:
int[] nums = {1, 2 ,3};
List test1 = Arrays.asList(nums);
So what's the reason behind it? After I removed Integer type of the List, isn't the compiler still assume the type is Integer? based on the type of nums?