Gets an ArrayList<String> of public and protected methods for the given Class . - Android java.lang.reflect

Android examples for java.lang.reflect:Method Get

Description

Gets an ArrayList<String> of public and protected methods for the given Class .

Demo Code


//package com.java2s;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;

public class Main {
    /**//  www  .jav  a2s.c  o m
     * Gets an {@link ArrayList<{@link String>} of <code>public</code> and <code>protected</code> 
     * methods for the given {@link Class}. 
     * 
     * @param parameterClass -{@link Class}
     * @return {@link ArrayList<{@link String>} -list of all method names.
     */
    @SuppressWarnings("unchecked")
    public static ArrayList<String> getAllMethodName(Class parameterClass) {
        ArrayList<String> methodNameList = new ArrayList<>();
        for (Method method : parameterClass.getDeclaredMethods()) {
            int modifiers = method.getModifiers();
            if (Modifier.isPublic(modifiers)
                    || Modifier.isProtected(modifiers)) {
                methodNameList.add(method.getName());
            }
        }
        return methodNameList;
    }
}

Related Tutorials