public static Method getMethod(Class<? extends Object> clazz, String methodName, Object... args)
            throws SecurityException, NoSuchMethodException {
        Method method = null;
        int length = args.length;
        Class<?>[] classes = new Class<?>[length];
        for (int i = 0; i < length; i++) {
            Object object = args[i];
            classes[i] = object.getClass();
        }
        try {
            method = clazz.getDeclaredMethod(methodName, classes);
        } catch (Exception e) {
        }
        if (method == null && args.length > 0) {
            Method[] methods = clazz.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                Method methodVar = methods[i];
                Class<?>[] types = methodVar.getParameterTypes();
                boolean isThisMethod = false;
                if (types.length == args.length) {
                    isThisMethod = true;
                    for (int j = 0; j < types.length && isThisMethod; j++) {
                        Class<?> type = types[j];
                        Object parameter = args[j];
                        if (!typeEquals(type, parameter)) {
                            isThisMethod = false;
                        }
                    }
                }
                if (isThisMethod) {
                    method = methodVar;
                    break;
                }
            }
        }
        return method;
    }
public static Method getMethod ( Class < ? extends Object > clazz , String methodName , Object ... args ) throws SecurityException , NoSuchMethodException { Method method = null ; int length = args . length ; Class < ? > [ ] classes = new Class < ? > [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { Object object = args [ i ] ; classes [ i ] = object . getClass ( ) ; } try { method = clazz . getDeclaredMethod ( methodName , classes ) ; } catch ( Exception e ) { } if ( method == null && args . length > 0 ) { Method [ ] methods = clazz . getDeclaredMethods ( ) ; for ( int i = 0 ; i < methods . length ; i ++ ) { Method methodVar = methods [ i ] ; Class < ? > [ ] types = methodVar . getParameterTypes ( ) ; boolean isThisMethod = false ; if ( types . length == args . length ) { isThisMethod = true ; for ( int j = 0 ; j < types . length && isThisMethod ; j ++ ) { Class < ? > type = types [ j ] ; Object parameter = args [ j ] ; if ( ! typeEquals ( type , parameter ) ) { isThisMethod = false ; } } } if ( isThisMethod ) { method = methodVar ; break ; } } } return method ; }
根据Class类、方法名和传入的参数，获取对应的方法对象 <br>
2013-10-21 下午4:49:19

@param clazz      Class类
@param methodName 方法名
@param args       参数
@return Method