这个语法有什么用:
function(String... args)
这和写作一样吗
function(String[] args)
仅在调用此方法时有区别,或者是否涉及任何其他功能?
两者之间的唯一区别是调用函数的方式。使用 String var args 您可以省略数组创建。
public static void main(String[] args) {
callMe1(new String[] {"a", "b", "c"});
callMe2("a", "b", "c");
// You can also do this
// callMe2(new String[] {"a", "b", "c"});
}
public static void callMe1(String[] args) {
System.out.println(args.getClass() == String[].class);
for (String s : args) {
System.out.println(s);
}
}
public static void callMe2(String... args) {
System.out.println(args.getClass() == String[].class);
for (String s : args) {
System.out.println(s);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)