我有以下代码:
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
为什么会这样?我以为原语是自动装箱的?