Pergunta

Isso me dá um erro:

int[] l = new int[] {0, 2, 192, -1, 3, 9, 2, 2};
int[] l2 = new int[] {9001, 7, 21, 4, -3, 11, 10, 10};
int[] l3 = new int[] {5, 5, 5, 64, 21, 12, 13, 200};

Set<List<Integer>> lists = new HashSet<List<Integer>>();
lists.add(Arrays.asList(l));

Eclipse: o método add(List<Integer>) no tipo Set<List<Integer>> não é aplicável aos argumentos (List<int[]>)

Eu pensei int era para ser auto -boxado para Integer?

Foi útil?

Solução

Embora o int seja auto -boxado para o número inteiro, int [] não é auto -boxado para inteiro [].

As matrizes não são encaixotadas, apenas os tipos em si.

Veja isso: Como converter int [] em listau003CInteger> em java? por soluções alternativas e pelas razões subjacentes.

Outras dicas

Vai Autobox de

Integer i = 1
int ii = i;

Mas você está tentando converter uma matriz e, quando tenta colocar uma variedade de primitivas como uma variedade de objetos, eles são diferentes.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top