Runtime Casting for array elements

U

u.Shanker

Hello !
I have to call ExternalClass.myMethod(InputClass[]) and want to change
InputClass and myMethods at runtime
see the code :
ExternalClass external = ...
InputClass rr = .....
InputClass[] array = new InputClass[] { rr };


Object o = anotherclass.getObjectInstance("InputClass");
Class cls = Class.forName("InputClass");
Object arr = Array.newInstance(cls, 1);
Array.set(arr, 0, o);
Class c = external.getClass();
Class[] parameterTypes = new Class[] {array}; // <-- this works

Method concatMethod;
Object[] arguments = new Object[] { };
Method[] mm = c.getMethods();
concatMethod = c.getMethod("myMethod", parameterTypes);

--
but I want arr instead of array.
Class[] parameterTypes = new Class[] {arr};

any comments
uma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,100
Latest member
MelodeeFaj
Top