本文主要是介绍Object...args的用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
可变参数,JDK1.5引入
/* public static void main(String[] args) {f1("12");//T,输出报异常 ArrayIndexOutOfBoundsException//f1("12",1,2,3,4,5); //T//f1("12",new int[]{1,2,3,4,5});// T}public static void f1(String s1, int... arg1) {System.out.println(s1);System.out.println(arg1[0]);}*/public static void main(String[] args) {//f1("12");//F//f1("12",1,2,3,4,5); //Ff1("12",new int[]{1,2,3,4,5});//T}public static void f1(String s1, int[] arg1) {System.out.println(s1);System.out.println(arg1[0]);}
以上环境:java version "1.8.0_181"
T表示正确,F表示错误
这篇关于Object...args的用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!