I
imran
hi,
I have a code that invoke methods by name. But in this code it just
invoke int a and int b. How can i modify to invoke another data,
String and Double. Actually i want to design fault injection tools.
Below is the code and can someone help me to solve the above problem.
I welcome with example source code.
Thank you....
import java.lang.reflect.*;
public class method2 {
public int add(int a, int b) //////// the problem here
{
return a + b;
}
public static void main(String args[])
{
try {
Class cls = Class.forName("method2");
Class partypes[] = new Class[2];
partypes[0] = Integer.TYPE;
partypes[1] = Integer.TYPE;
Method meth = cls.getMethod( "add", partypes);
method2 methobj = new method2();
Object arglist[] = new Object[2];
arglist[0] = new Integer(37);
arglist[1] = new Integer(47);
Object retobj = meth.invoke(methobj, arglist);
Integer retval = (Integer)retobj;
System.out.println(retval.intValue());
}
catch (Throwable e) {
System.err.println(e);
}
}
}
I have a code that invoke methods by name. But in this code it just
invoke int a and int b. How can i modify to invoke another data,
String and Double. Actually i want to design fault injection tools.
Below is the code and can someone help me to solve the above problem.
I welcome with example source code.
Thank you....
import java.lang.reflect.*;
public class method2 {
public int add(int a, int b) //////// the problem here
{
return a + b;
}
public static void main(String args[])
{
try {
Class cls = Class.forName("method2");
Class partypes[] = new Class[2];
partypes[0] = Integer.TYPE;
partypes[1] = Integer.TYPE;
Method meth = cls.getMethod( "add", partypes);
method2 methobj = new method2();
Object arglist[] = new Object[2];
arglist[0] = new Integer(37);
arglist[1] = new Integer(47);
Object retobj = meth.invoke(methobj, arglist);
Integer retval = (Integer)retobj;
System.out.println(retval.intValue());
}
catch (Throwable e) {
System.err.println(e);
}
}
}