I have a method like:
void foo(int x, Grok... groks);
There’s no way to define a method that returns a type of varargs, right? Ideally I want an additional util method:
foo(25, new Grok(), new Grok(), generateMoreGroks());
public Grok... generateMoreGroks() {
return new Grok[] {
new Grok(), new Grok(), new Grok() };
}
right?
—- More info ————–
The issue with the above is that we can’t mix a few Grok instances allocated there with an array of Groks:
"new Grok(), new Grok(), generateMoreGroks());"
and I don’t think that’s legal, unless you could define a method to return a type of vararg (I guess).
Thanks
You can do,
If a method takes a varargs parameter, it is the same as taking an array.
Now you need to overload foo to allow it to take some Grok instances, and the rest as varargs,
Where foo methods are like,
This is a bit ugly.