没时间解释,先上代码,改日再编辑
package test;
import java.lang.reflect.Method;
class Foo {
public String fool(String[] say) {
for (String i : say)
System.out.println("I want to say :" + i);
return "success";
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("main started...");
try {
Class<Foo> c = Foo.class;
System.out.println("c = " + c);
Object invoker = c.newInstance();
System.out.println("invoker = " + invoker.getClass());
Method m = c.getMethod("fool", new Class[] { String[].class });
System.out.println(m.invoke(invoker, new Object[] { new String[]{"1", "2", "3"} }));
} catch (Exception e) {
e.printStackTrace();
}
}
}