get Method from current class or parent class - Android java.lang.reflect

Android examples for java.lang.reflect:Method Get

Description

get Method from current class or parent class

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    public static Method getMethod(Class clazz,
            boolean methodDeclaredInClass, String methodName,
            Class methodArgsTypes[]) throws Exception {
        Method method;//from   w  ww.j  av  a  2  s .  co  m
        if (methodDeclaredInClass)
            method = clazz.getDeclaredMethod(methodName, methodArgsTypes);
        else
            method = clazz.getMethod(methodName, methodArgsTypes);
        if (!method.isAccessible())
            method.setAccessible(true);
        return method;
    }
}

Related Tutorials