为什么编译失败会失败?将包装类拆箱到var-arg
class ZiggyTest {
public static void main(String[] args){
Integer[] i = {1,2,3,4};
test(i);
}
public static void test(int... s){
for (int x : s){
System.out.println(x);
}
}
}
ZiggyTest.java:26: test(int...) in ZiggyTest cannot be applied to (java.lang.Integer[])
test(i);
^
1 error
什么是规则,当涉及到拆箱包装阵列VAR-ARGS。
如果我阵列声明为
int[] j = {1,2,3,4};
test(j);
w帽子是班[我? – ziggy 2011-12-29 15:53:12
这是int数组的类类型。我 - 代表int,[ - 代表一维数组 – 2011-12-29 15:58:57