Java Reflection Method Get from Object getMethodNames(Object obj, boolean hasParent)

Here you can find the source of getMethodNames(Object obj, boolean hasParent)

Description

get Method Names

License

Apache License

Declaration

public static String[] getMethodNames(Object obj, boolean hasParent) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {

    public static String[] getMethodNames(Object obj, boolean hasParent) throws Exception {
        Method[] methods = getMethods(obj, hasParent);
        int len = methods.length;
        if (len < 1) {
            return null;
        }/*from w w  w  . java  2  s  .c o  m*/
        String[] names = new String[len];
        for (int i = 0; i < len; i++) {
            Method m = methods[i];
            names[i] = m.getName();
        }

        return names;
    }

    public static Method[] getMethods(Object obj, boolean hasParent) throws Exception {
        if (isEmpty(obj)) {
            return null;
        }

        if (hasParent)
            return obj.getClass().getMethods();
        return obj.getClass().getDeclaredMethods();
    }

    public static boolean isEmpty(Object obj) throws Exception {
        return obj == null;
    }
}

Related

  1. getMethodIgnoreCaseWithNoParams(Object o, String p)
  2. getMethodInHolder(String methodName, Object holder)
  3. getMethodInstace(Class c, Object inst, String name, Class[] types, boolean access)
  4. getMethodName(AccessibleObject method)
  5. getMethodNamed(String methodName, Object holder)
  6. getMethodNames(Object obj, boolean includeInheritedMethods)
  7. getMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)
  8. getMethodObject(Object object, String method, Object[] parametre)
  9. getMethodResult(final Object element, final String methodName)