I am not sure of the vocabulary I am using here, please correct me if I'm wrong.
In Javascript, I had the following code:
let args = [1,2,3];
function doSomething (a, b, c) {
return a + b + c;
}
doSomething(...args);
As you can see, when calling doSomething
, I am able to use the ...
spread operator in order to "transform" my arguments into 1, 2, 3
.
Now, I'm trying to do the same thing with Java.
Let's say I have a Foo
class:
public class Foo {
public int doSomething (int a, int b, int c) {
return a + b + c;
}
}
And now I want to call the doSomething
:
int[] args = {1, 2, 3};
I'd like to use something like doSomething (...args)
instead of calling doSomething(args[0], args[1], args[2])
.
I saw that this is possible in the declaration of functions, but I'd like not to change the implementation of such a function.