I'm pretty new to Java, so I'm hoping one of you guys knows how to do this. I'm having the user specify both the type and value of arguments, in any XML-like way, to be passed to methods that are external to my application.
Example: javac myAppsName externalJavaClass methodofExternalClass [parameters]
Of course, to find the proper method, we have to have the proper parameter types as the method may be overloaded and that's the only way to tell the difference between the different versions. Parameters are currently formatted in this manner:
(type)value(/type), e.g. (int)71(/int) (string)This is my string that I'm passing as a parameter!(/string)
I parse them, getting the constructor for whatever type is indicated, then execute that constructor by running its method, newInstance(<String value>)
, loading the new instance into an Object
. This works fine and dandy, but as we all know, some methods take arrays, or even multi-dimensional arrays.
I could handle the argument formatting like so: (array)(array)(int)0(/int)(int)1(/int)(/array)(array)(int)2(/int)(int)3(/int)(/array)(/array)
... or perhaps even better... {{(int)0(/int)(int)1(/int)}{(int)2(/int)(int)3(/int)}}
.
The question is, how can this be implemented? Do I have to start wrapping everything in an Object[] array so I can handle primitives, etc. as argObj[0], but load an array as I normally would? (Unfortunately, I would have to make it an Object[][] array if I wanted to support two-dimensional arrays. This implementation wouldn't be very pretty.)