Domanda

Questo mi dà un errore:

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: Il metodo add(List<Integer>) nel tipo Set<List<Integer>> non è applicabile per gli argomenti (List<int[]>)

Ho pensato int doveva essere autoboxed a Integer?

È stato utile?

Soluzione

Anche se int è autoboxed a Integer, int [] non è Autoboxed a Integer [].

Gli array non sono boxed, solo i tipi stessi.

Vedere questo: Come convertire int [] in List in Java? per soluzioni alternative e le relative motivazioni.

Altri suggerimenti

Sarà autobox da

Integer i = 1
int ii = i;

Ma, si sta tentando di convertire un array, e quando si cerca di mettere una serie di primitive come un array di oggetti sono diversi.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top