Java多参数方法test(String... params)

Java多参数方法,就是说在不清楚参数应该放多少情况下,只写一个方法就能实现。

可以参考Method.invoke(obj, args)这个方法,当然其他类也会有这里就不讨论了。


 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Params {
     /**
      * 任意参数方法
      * @param params 参数
      * */
     public static void test(String... params){
         //遍历参数内容
         for (String temp : params){
             System.out.print(temp);
         }
         System.out.println();
     }
     
     
     public static void main(String[] args) {
         Params.test( "a" , "a" , "a" );
         Params.test( "b" , "b" );
         Params.test( "c" );
     }
 
}




转自: http://www.yl-blog.com/index.php/class/37.html

你可能感兴趣的:(android,字体)