求助 动态选择方法 如何实现 大虾帮忙给个思路~~ 反射,获得字符串"ABC"后调用A("BC"),在A中根据参数"BC"调用B("C"),在B中根据参数"C"调用C(""),就ok了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); }} ★★★java socket linux本地服务器通信的性能问题 关于java线程的问题 JAVA FOR语句问题 新手指教 谢谢 问个移位运算的问题 求助各位高手这样的程序该如何做 在广州JAVA程序员月薪大概在多少RMB左右? 迷茫 请教,关于 RMI 请问Oracle8.1.7有专用的JDBC3.0驱动吗? 不知道它在哪一个jar包中? 还是JDBC中的问题,麻烦在进来看下
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);
}
}