//正确声明方式
public static void dealArray(int... intArray){
}
}
public static void dealArray(int... intArray, int count){ //编译报错,可变参数类型应该作为参数列表的最后一项
}
}
//声明0到多个int类型的参数
package com.mw.mbox.boss.util;
public class Test {
public void run(int...is){
if(is!=null && is.length>0){
for (int i = 0; i < is.length; i++) {
System.out.println("@@@@@");
}
}
}
public static void main(String[] args) {
Test test = new Test();
test.run(123,234);
}
}
public class Test {
public void run(int...is){
if(is!=null && is.length>0){
for (int i = 0; i < is.length; i++) {
System.out.println("@@@@@");
}
}
}
public static void main(String[] args) {
Test test = new Test();
test.run(123,234);
}
}
本文介绍了Java中使用可变参数的方法及注意事项,展示了如何定义接受任意数量int类型参数的方法,并通过实例演示了方法的调用过程。
8194

被折叠的 条评论
为什么被折叠?



