methodutil.java

来自「办公自动化项目」· Java 代码 · 共 46 行

JAVA
46
字号
package hong.javanet.util;
import java.lang.reflect.*;

/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author 洪桃李
 * @version 2.0
 */
public class MethodUtil {
    public static Object invoke(Object target,String methodName) {
        try {
            Method method = target.getClass().getMethod(methodName, new Class[0]);
            return method.invoke(target,new Object[0]);
        } catch (Throwable ex) {
            throw ExceptionUtil.wrapException(ex);
        }
    }
    public static Object invoke(Object target,String methodName,String parameter) {
        try {
            Method method = target.getClass().getMethod(methodName,
                    new Class[] {String.class});
            return method.invoke(target,new Object[]{parameter});
        } catch (Throwable ex) {
            throw ExceptionUtil.wrapException(ex);
        }
    }
    public static Object invoke(Object target,String methodName,
                                Class[] paramClasses, Object[] parameters) {
    try {
        Method method = target.getClass().getMethod(methodName, paramClasses);
        return method.invoke(target,parameters);
    } catch (Throwable ex) {
        throw ExceptionUtil.wrapException(ex);
    }
}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?