Import Java.lang.reflect.Method;
public class Testreflect {/** * @param args */public static void main (string[] args) {try {Wu w=new Wu ();
Object[] Argspara=new object[]{};
Testreflect.invokemethod (W, "Outinfo", Argspara);
Argspara=new object[]{"WU"};
Testreflect.invokemethod (W, "Outinfo", Argspara);
Argspara=new object[]{"WU", 2};
Testreflect.invokemethod (W, "Outinfo", Argspara);
catch (Exception e) {e.printstacktrace (); /** * Reflection Invocation Method * @param newObj an object * @param the method name of the MethodName object * @param args parameter array * @return return value * @t
Hrows Exception */public static object InvokeMethod (Object newObj, String methodname, object[] args) throws Exception {
Class Ownerclass = Newobj.getclass ();
class[] Argsclass = new Class[args.length];
for (int i = 0, j = args.length I < J; i++) {Argsclass[i] = Args[i].getclass ();
Method method = Ownerclass.getmethod (methodname, Argsclass);
Return Method.invoke (NEWOBJ, args); }
}
Class wu{public void Outinfo () {System.out.println ("Wu.outinfo");
public void Outinfo (string s) {System.out.println ("Wu.outinfo (string s):" +s);
public void Outinfo (string S,integer N) {System.out.println ("Wu.outinfo (String s,int N):" +s+n); }
}