public void setError(Enum errorType, String... errStr) 后面那个参数表示变长参数,你可以输入多个string类型的值,相当于一个数组.不过这个参数必须放在最后.因为放在前面的话,如果后面又跟了同类型的参数,编译器无法识别你输入的值到底输入哪个参数.
public class Main { public static void main(String[] args) { test("hello"); test("hello","world"); test("hello","world","china"); } public static void test(String...args){ for (int i = 0; i < args.length; i++) { System.out.print(args[i]+" "); } System.out.println(); } }
省略号
那是说参数列表里String个数不定
jdk 5 的新特性。相当于后面可以输入多个string参数。其实也就是相当于一个String[]
后面那个参数表示变长参数,你可以输入多个string类型的值,相当于一个数组.不过这个参数必须放在最后.因为放在前面的话,如果后面又跟了同类型的参数,编译器无法识别你输入的值到底输入哪个参数.
public class Main {
public static void main(String[] args) {
test("hello");
test("hello","world");
test("hello","world","china");
}
public static void test(String...args){
for (int i = 0; i < args.length; i++) {
System.out.print(args[i]+" ");
}
System.out.println();
}
}