为什么要使用在String参数中传递的名称来调用方法?您不能为不同的动作创建一个常量,然后使用
switch并在每种情况下调用带有参数的方法
i吗?
您将受益于编译器检查代码中的错误。
编辑 :如果您确实要使用反射,请使用以下方法检索
Method对象:
Method m = YourClass.class.getMethod("method_name",new Class[] { Integer.class })我猜可能是Integer.class。然后将方法调用为
m.invoke(null,123); //first argument is the object to invoke on, ignored if static method



