Por que o java não autobox int [] para Inteiro []
Quando eu faço o seguinte,
arrayList1
- contém um elemento e é umint[]
.arrayList2
- não compilando (erro: o construtorArrayList<Integer>(List<int[]>)
está indefinido)arrayList3
- contém 7 elementos e sãoInteger
objetosAqui está o código:
int[] intArray = new int[]{2,3,4,5,6,7,8};
ArrayList arrayList1 = new ArrayList(Arrays.asList(intArray));
ArrayList<Integer> arrayList2 = new ArrayList<Integer>(Arrays.asList(intArray));
Integer[] integerArray = new Integer[]{2,3,4,5,6,7,8};
ArrayList<Integer> arrayList3 = new ArrayList<Integer>(Arrays.asList(integerArray));
Pergunta, questão : Por que o compilador não coloca os elementos automaticamente noint[]
paraInteger
e crie umArrayList<Integer>
? Qual é a razão por trás disso? Essa é a minha estupidez ou algum outro motivo?