get Declared Method by method name - Android java.lang.reflect

Android examples for java.lang.reflect:Method Get

Description

get Declared Method by method name

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {

    public static Method getDeclaredMethod(Object object,
            String methodName, Class<?>... parameterTypes) {
        Method method = null;//from w ww  . ja v a2s. co m

        for (Class<?> clazz = object.getClass(); clazz != Object.class; clazz = clazz
                .getSuperclass()) {
            try {
                method = clazz
                        .getDeclaredMethod(methodName, parameterTypes);
                return method;
            } catch (Exception e) {

            }
        }

        return null;
    }
}

Related Tutorials