In the following examples:
class ZiggyTest2{ public static void main(String[] args){ int[] a = { 1, 2, 3, 4,7}; List<Integer> li2 = new ArrayList<Integer>(); li2 = Arrays.asList(a); } }
The compiler complains that int [] and java.lang.Integer are incompatible. those.
found : java.util.List<int[]> required: java.util.List<java.lang.Integer> li2 = Arrays.asList(a); ^
It works fine if I change the list definition to remove generic types.
List li2 = new ArrayList();
- Should the compiler automatically put int in Integer?
- How can I create a
List<Integer>
object from an ints array using Arrays.asList ()?
thanks
ziggy
source share