Java: ¿Por qué no se autoboxing pasando aquí?
-
21-09-2019 - |
Pregunta
Esto me da un error:
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: El
add(List<Integer>)
método en elSet<List<Integer>>
tipo no es aplicable para los argumentos (List<int[]>
)
pensé int
se suponía que se autoboxed a Integer
?
Solución
Aunque int se autoboxed a Integer, int [] no se Autoboxed a entero [].
Las matrices no están en caja, sólo los tipos mismos.
Vea esto: Cómo convertir int [] en la lista
Otros consejos
Se AUTOBOX de
Integer i = 1
int ii = i;
Sin embargo, se está intentando convertir una matriz, y cuando se trata de poner una serie de primitivas como una serie de objetos que son diferentes.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow