Hi,
Thanks for the reply. Here is what I am trying to do.
I have a method "setInputParameters( HashMap map )". The values to the
HashMap can be a string, array of strings, arrays of primititve types
(int[], long[] etc).
Here is a sample usage scenario.
HashMap map = new HashMap();
int[] a = { 1, 2, 4, 5 };
String[] b = { "foo", "bar", "goo" };
String c = "xyz";
Integer d = new Integer( 10 );
map.put( "PARAM1", a );
map.put( "PARAM2", b );
map.put( "PARAM3", c );
map.put( "PARAM4", d );
FOO.setInputParameters( map );
In the setInputParameters I want to get these values as string array or
String depending on whethere the parameter is Object or an array of object.
I want to extract the infromation from the map and convert them as
String[] a = { "1", "2", "4", "5" };
String[] b = { "foo", "bar", "goo" };
String c = "xyz";
Stirng d = "10";
Hope this is clear.
Anand
>>Hi,
>>
[quoted text clipped - 13 lines]
> don't see where arrays enter the picture), please explain
> more fully what you're trying to do.
Eric Sosman - 14 Mar 2005 17:12 GMT
A: Reading in reverse too much like Yoda-speak is.
Q: What is the impediment?
A: Because it impedes understanding.
Q: Why is top-posting deprecated?
> [...]
> HashMap map = new HashMap();
[quoted text clipped - 16 lines]
> String c = "xyz";
> Stirng d = "10";
Someone else may have a better solution, but all I can
think of is to fetch an Object from the Map, make a run-time
determination of its class (using instanceof and/or fancier
reflection techniques), and then process it according to
your whim. This would take care of the values, but as far
as I can see there is no possibility of recovering the names
of the variables -- maybe you just used a,b,c,d twice by
coincidence, but if you had the intention of using `x42' to
plunk a value into the Map and then somehow magically plucking
a new `x42' back out of it, I think you're doomed.
Overall, I don't think this approach is a good one. The
general idea of object-oriented design is that the objects
implement their own behaviors; as soon as you start writing
"if it's a This do that(), else if it's an Other do ..." you
are separating the implementation from the object. There are
circumstances where this makes sense, but if you find yourself
doing it frequently it may be time to step back and re-think
the design.

Signature
Eric.Sosman@sun.com