日期:2014-05-20 浏览次数:20752 次
package test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test {
@SuppressWarnings("unused")
public static void main(String[] args) {
schedule("abc");
}
static void schedule(String methods) {
Test t=new Test();
if (methods.length()==0) {
return;
}
String m=methods.substring(0,1);
String p=methods.substring(1);
try {
Method method=Test.class.getDeclaredMethod(m,String.class);
method.invoke(t,p);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
void a(String methods) {
System.out.println("Test.a()");
schedule(methods);
}
void b(String methods) {
System.out.println("Test.b()");
schedule(methods);
}
void c(String methods) {
System.out.println("Test.c()");
schedule(methods);
}
void d(String methods) {
System.out.println("Test.d()");
schedule(methods);
}
}