我有以下代码:自动装盒不工作?
static boolean nextPerm(int[] A) {
int N = A.length;
int k = N - 1;
int[] S = { };
while (k >= 0) {
if (S.length > 0 && containsLarger(S, A[k])) {
int v = firstLargest(S, A[k]);
//int vIndex = Arrays.asList(S).indexOf(v);
List<Integer> test = Arrays.asList(S); // // ERRORS HERE. Before error, S is { 2 }
System.out.println(test.get(0));
int vIndex = test.indexOf(S);
S[vIndex] = A[k];
A[k] = v;
System.arraycopy(S, 0, A, k + 1, N - k);
return true;
} else {
S = addIntAscend(S, A[k]);
k -= 1;
}
}
return false;
}
错误之前,S是一个int数组{2}。当我将TEST设置为Arrays.asList(S)时发生错误:
Perms.java:44: error: incompatible types
List<Integer> test = Arrays.asList(S);
^
required: List<Integer>
found: List<int[]>
1 error
为什么会发生这种情况?我认为原始图像是自动复制的?
但是看看下面这个例子。 http://stackoverflow.com/a/6171675/2288418他将一个int数组传递给asList,并能够获取它的索引。编辑:没关系,他的例子LOL中有一个错误。 –