Lets say I pass my arguments into my function like this.
Seems the Object outside arguments knows it's a Object[]
array.
But the Object[]
inside it are not Object Array's but plain Object's
Object[] arguments = {
new Object[] {"command", "value"},
new Object[] {"List_test", Arrays.asList("1", "2", "3", "4")},
new Object[] {"single command"}
};
myFunc(arguments);
public void myFunc(Object[] args) {
if(args == null || args.length == 0) {
System.out.println("Error!");
return;
}
//How I do this below?
for(Object objArray : args) { //this one is good.
if(objArray == null) continue;
//objArray = (Object[]) objArray; //can't figure this out.
for(Object eachObject : objArray) { //this don't work.
System.out.println("eachObject reference = " + eachObject);
}
}
for(Object[] objArray : args) { //this don't work.
if(objArray == null) continue;
for(Object eachObject : objArray) { //this don't work.
System.out.println("eachObject reference = " + eachObject);
}
}
}
I tried this in Java Console
> for(Object[] a : arguments) { System.out.println(a); }
Got this error
Static Error: Bad types in assignment: from Object to Object[]
This looks much worse.
Object[][] arguments = {
{ new Object[]{"command", "value"}},
{ new Object[]{"List_test", Arrays.asList("1", "2", "3", "4")}},
{ new Object[]{"single command"}}
};