K
Kamal Zamli
Hi all
I need help on the following code...I have a user defined class
called Kucing. I need to invoke a method called add using reflection.
Now, I can make the code works if kuci is a single object.
How can I change the code to make use an array of kuci...and be able
to invoke the method "add" through reflection
....
public String add (Kucing kuci[],String b)
......
partypes [0] = Kucing.class; // Dont know how to specify an array ????
----------------------------------------------------------
package tip2;
import java.lang.reflect.*;
public class method2
{
public String add (Kucing kuci, String b)
{
return kuci.get()+" = "+ b;
}
public static void main (String args[])
{
try
{
Class cls = Class.forName("tip.method2");
Class partypes[] = new Class [2];
partypes [0] = Kucing.class;
partypes [1] = String.class; //
Method meth = cls.getMethod ("add", partypes);
method2 methodobj = new method2 ();
Object arglist[] = new Object[2];
arglist [0] = new Kucing ();
arglist [1] = new String ("Kamal Test");
Object retobj = meth.invoke(methodobj, arglist);
System.out.println ((String) retobj);
}
catch (Throwable e)
{
System.err.println(e);
}
}
}
I need help on the following code...I have a user defined class
called Kucing. I need to invoke a method called add using reflection.
Now, I can make the code works if kuci is a single object.
How can I change the code to make use an array of kuci...and be able
to invoke the method "add" through reflection
....
public String add (Kucing kuci[],String b)
......
partypes [0] = Kucing.class; // Dont know how to specify an array ????
----------------------------------------------------------
package tip2;
import java.lang.reflect.*;
public class method2
{
public String add (Kucing kuci, String b)
{
return kuci.get()+" = "+ b;
}
public static void main (String args[])
{
try
{
Class cls = Class.forName("tip.method2");
Class partypes[] = new Class [2];
partypes [0] = Kucing.class;
partypes [1] = String.class; //
Method meth = cls.getMethod ("add", partypes);
method2 methodobj = new method2 ();
Object arglist[] = new Object[2];
arglist [0] = new Kucing ();
arglist [1] = new String ("Kamal Test");
Object retobj = meth.invoke(methodobj, arglist);
System.out.println ((String) retobj);
}
catch (Throwable e)
{
System.err.println(e);
}
}
}