So basically from my searches on StackOverflow, this popped out (correct me if wrong):
You can define function that accepts variable argument (in this case any Object) count this way:
public void varadric(Object... arguments) { //I'm a dummy function }
You call this method with any count of arguments (which extend Object) and you'll get one argument being
Object[]
in the function:public static main() { varadric("STRING", new ArrayList<int>()); } public void varadric(Object... arguments) { System.out.println("I've received "+arguments.length+" arguments of any Object subclass type."); }
You can instead somehow generate the input as Object[] array and pass as a single parameter without any change:
public static main() { Object[] args = new Object[2]; args[0] = "STRING"; args[1] = new ArrayList<int>()); //Should say it got 2 arguments again! varadric(args); }
Now my question is: Since Object[]
implements Object
too, does it mean it's not possible to pass it in varargs (ending up with nested array?)?
Imagine following scenario with more specific description:
public void varadric(Object[]... arguments) {
//I'm a function that expects array of arrays
// - but I'm not sure if I'll allways get that
}
Could someone make this clear for me?