get Class Method by class name and method parameters - Android java.lang.reflect

Android examples for java.lang.reflect:Method Get

Description

get Class Method by class name and method parameters

Demo Code


//package com.java2s;
import java.lang.reflect.*;

public class Main {
    public static Method getClassMethod(Class clazz, String methodName,
            Class<?>... fieldParams) throws NoSuchMethodException {
        try {/*from   w w  w.  j  av  a  2 s.c o m*/
            return clazz.getDeclaredMethod(methodName, fieldParams);
        } catch (NoSuchMethodException e) {
            Class superClass = clazz.getSuperclass();
            if (superClass == null) {
                throw e;
            } else {
                return getClassMethod(superClass, methodName, fieldParams);
            }
        }
    }
}

Related Tutorials