I want to be able to write an array directly as a parameter for my method, instead of storing the array values inside a separate variable.
Example:
public void myMethod(myObject[] objParam, String[] strParam, Integer[] intParam) {
// do stuff
}
And I would like to call the method like this:
myMethod({obj1, obj2}, {"string1","string2"}, {123,456});
Currently this is not acceptable in my IDE, and I've tried different notations, even casting to arrays, however nothing works.
I don't want to have to declare and initiate an array for each of the parameters every time I need to use my method.
Does anyone know a good workaround for this? Is using List a solution?
EDIT: The parameter types are fixed, the array values will correspond 1 to 1 for each of the 3 parameters.
new Object[]{obj1, obj2}should do it, or is that exactly what you're trying to avoid in the first place? I'm afraid there's no shorter way to specify an array in Java. And List/Set/Map is even more verbose.myMethod(new myObject[]{obj1, obj2}, new String[]{"string1","string2"}, new Integer[]{123,456});?