public class RandomArray {
public void test(int...x){
System.out.println("test");
}
public static void main(String[] args){
RandomArray ra = new RandomArray();
ra.test();
ra.test(1);
ra.test(1,2);
ra.test(new int[]{1,2});
}
}
而且你可以再在这个类中添加方法:
- Java code
-
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> public void test(){ } public void test(int x){ } public void test(int x,int y){ }
但是你不能添加:
- Java code
-
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> public void test(int[] x){ }
会报一个重复定义方法的错误。
因为jvm在编译test(int...x)时,就是按照test(int[] x)来编译的。