Java Arrays asList(int)
2021-6-4 anglehua
While doing simple program I noticed this issue. int[] example = new int[10]; ListCompilation error is returned as cannot convert from List I am not questioning about autoboxing here I just wondered how Arrays.asList can return List asList implementation is public staticSo it is treating int[] as T that is why this is happening.
There is no automatic autoboxing done of the underlying ints in Arrays.asList.
Arrays.asList(...) works perfectly to transform an array of objects into a list of those objects. Also, Arrays.asList(...) is defined in Java 5 with a varag construct, or, in order words, it can accept an undefined number of parameters in which case it will consider all of those parameters as members of an array and then return a List instance containing those elements. List |