K
Kamal Zamli
Dear all
I have the following question on Java reflection. Consider the
following code:
-----------------------------------------------------------
import java.lang.reflect.*;
public class method2
{
public String add (int a[])
{
return "done";
}
public static void main (String args[])
{
try
{
Class cls = Class.forName("method2");
Class partypes[] = new Class [1];
partypes [0] = Integer[].class;
Method meth = cls.getMethod ("add", partypes);
method2 methobj = new method2 ();
Object arglist[] = new Object[1];
arglist [0] = new Integer[]{ new Integer(25),new Integer(24)};
Object retobj = meth.invoke(methobj, arglist);
System.out.println ((String) retobj);
}
catch (Throwable e)
{
System.err.println(e);
}
}
}
Here is my question, I could not seem to be able to invoke method add
using reflection with array of integer as parameter.
(java.lang.NoSuchMethodException is thrown)...
Tried the following code:
............
Class cls = Class.forName("method2");
Class partypes[] = new Class [1];
partypes [0] = Integer[].TYPE;
^^^^^^^^^^^^^^^
Got syntax error... Any hints ?
Thanks in advance
I have the following question on Java reflection. Consider the
following code:
-----------------------------------------------------------
import java.lang.reflect.*;
public class method2
{
public String add (int a[])
{
return "done";
}
public static void main (String args[])
{
try
{
Class cls = Class.forName("method2");
Class partypes[] = new Class [1];
partypes [0] = Integer[].class;
Method meth = cls.getMethod ("add", partypes);
method2 methobj = new method2 ();
Object arglist[] = new Object[1];
arglist [0] = new Integer[]{ new Integer(25),new Integer(24)};
Object retobj = meth.invoke(methobj, arglist);
System.out.println ((String) retobj);
}
catch (Throwable e)
{
System.err.println(e);
}
}
}
Here is my question, I could not seem to be able to invoke method add
using reflection with array of integer as parameter.
(java.lang.NoSuchMethodException is thrown)...
Tried the following code:
............
Class cls = Class.forName("method2");
Class partypes[] = new Class [1];
partypes [0] = Integer[].TYPE;
^^^^^^^^^^^^^^^
Got syntax error... Any hints ?
Thanks in advance