62,634
社区成员




SwingUtilities.invokeAndWait([arbitrary thread])
SwingUtilities.invokeAndWait([arbitrary thread])
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class FunctionPointer {
public static Method getMethod(Object o, String funcName, Object[] params) {
Method m = null;
Class c = null;
Class[] p = null;
if (o != null) {
c = o.getClass();
}
if (params != null) {
p = new Class[params.length];
for (int i = 0; i < params.length; i++) {
p[i] = params[i].getClass();
}
}
if (funcName != null && c != null && p != null) {
try {
m = c.getMethod(funcName, p);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
return m;
}
public void test(String name){
System.out.println("Hello " + name);
}
public static void main(String args[]){
FunctionPointer f = new FunctionPointer();
try {
FunctionPointer.getMethod(f, "test", new Object[]{"bzwm"}).invoke(f, "bzwm");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}