public void foo(Integer... ids) {
Integer... fIds = bar(ids);
}
public void bar(Integer... ids) {
// I would like to eliminate few ids and return a subset. How should I declare the return argument
}
我应该如何声明 bar 的返回类型?
最佳答案
您可以将 vararg 参数作为数组引用。
public Integer[] bar(Integer... ids) {
..
}
It is still true that multiple arguments must be passed in an array, but the varargs feature automates and hides the process
对于jvm来说这实际上是一个数组,编译器隐藏了数组的创建。
关于java - 我应该如何声明可变参数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6197895/