- class Hello{
-
- public static void generalUse(int []args){
- for (int i = 0;i < args.length ; i++ ){
- System.out.println(args[i]);
- }
- }
-
- public static void newBehaviour(int... args){
- for (int i = 0;i < args.length ; i++ ){
- System.out.println(args[i]);
- }
- }
-
- public static void main(String[] args) {
- //int[] a = {};
- //test1
- generalUse(); //不能通过编译,
- newBehaviour();
-
- }
- }
-
通过测试看到,当参数为(int... arg) 与传统的(int [] args) 在调用时,但不传入参数时,
传统的使用将不能通过编译:
关于 method (Object ... params )
原文:http://my.oschina.net/nly/blog/311694