F
Faiser
Hello,
I am having trouble invoking a method that accepts a variable amount
of parameters via run time reflection. I locate the method a
signature of the method with:
Method m = targetClass.getDeclaredMethod( "methodName",
ArgType[].class )
Where the method declaration looks like:
public ReturnObj methodName( ArgType .... args ) { /* method body....
/* }
This works fine. At run time, however, I try to invoke the method
with zero arguments with:
ReturnObj o = (ReturnObj)m.invoke( target );
Where target is an instantiated target class, m is the method from
above, and the return value is of the correct type.
This unfortunately results in the following exception: "Exception in
thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: wrong
number of arguments".
Practically I assume I could solve this problem by passing in a zero
lengthed array, or even a null value. I am curious though to see if
any one else has found a more consistent i.e. elegant solution. Would
anyone who's encountered this please offer any comments if they were
able to solve this in another way?
Thank you.
-Faiser
I am having trouble invoking a method that accepts a variable amount
of parameters via run time reflection. I locate the method a
signature of the method with:
Method m = targetClass.getDeclaredMethod( "methodName",
ArgType[].class )
Where the method declaration looks like:
public ReturnObj methodName( ArgType .... args ) { /* method body....
/* }
This works fine. At run time, however, I try to invoke the method
with zero arguments with:
ReturnObj o = (ReturnObj)m.invoke( target );
Where target is an instantiated target class, m is the method from
above, and the return value is of the correct type.
This unfortunately results in the following exception: "Exception in
thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: wrong
number of arguments".
Practically I assume I could solve this problem by passing in a zero
lengthed array, or even a null value. I am curious though to see if
any one else has found a more consistent i.e. elegant solution. Would
anyone who's encountered this please offer any comments if they were
able to solve this in another way?
Thank you.
-Faiser