get Declared Method from current class - Android java.lang.reflect

Android examples for java.lang.reflect:Method Get

Description

get Declared Method from current class

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;// w  w  w  .  j a v a 2  s .  com

        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