Java方法具有无限的参数 [英] Java method with unlimited arguments
本文介绍了Java方法具有无限的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Spring框架的使用方法,在这里,只要你喜欢,你可以传递尽可能多的参数。
The spring framework uses methods where you can pass as many arguments as you like.
我想编写一个函数,也可以采取数据无限量的。怎么叫这个功能让我能读到它。或者,我该怎么界定呢?
I would like to write a function that can also take an unlimited amount of data. How is this feature called so that I can read about it. Or how can I define it?
太感谢了。
推荐答案
这就是所谓的可变参数。
它允许采取任何数目的参数的方法。它们是在该方法的阵列访问:
It allows a method to take any number of arguments. They are accessible as an array in the method:
public void foo(String... args) {
for (String arg : args) {
// do smth with arg.
}
}
这是语法糖。编译器隐藏了数组创建,所以不是
This is syntactic sugar. The compiler hides the array creation, so instead of
bar.foo(new String[] {"1", "2", "3"});
你写
bar.foo("1", "2", "3");
这篇关于Java方法具有无限的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文