Java Utililty Methods Reflection Method Get from Object

List of utility methods to do Reflection Method Get from Object

Description

The list of methods to do Reflection Method Get from Object are organized into topic(s).

Method

SetgetMethodNames(Object obj, boolean includeInheritedMethods)
get Method Names
HashSet<String> methodNames = new HashSet<String>();
if (obj == null)
    return methodNames;
Method[] methods = null;
if (includeInheritedMethods) {
    methods = obj.getClass().getMethods();
} else {
    methods = obj.getClass().getDeclaredMethods();
...
ObjectgetMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)
get Method Object
Object o = getMethodObject(clazz, method, args, object, objects);
return o == null ? null : type.cast(o);
ObjectgetMethodObject(Object object, String method, Object[] parametre)
get Method Object
Object str = null;
Class[] classes = null;
if (parametre != null) {
    classes = new Class[parametre.length];
    for (int i = 0; i < classes.length; i++)
        classes[i] = parametre[i].getClass();
try {
...
ObjectgetMethodResult(final Object element, final String methodName)
get Method Result
return getMethodResult(element, methodName, null);
ObjectgetMethodReturn(String className, String methodName, Class[] params, Object[] args, boolean isStatic)
get Method Return
Class<?> clazz = Class.forName(className);
Object instance = clazz.newInstance();
Method method = clazz.getMethod(methodName, params);
if (isStatic) {
    return method.invoke(null, args);
} else {
    return method.invoke(instance, args);
ClassgetMethodReturnTypeGeneric(Object source, Method method)
Tries to retrieve the generic parameter of an ObjectProperty return by a method at runtime.
Type type = method.getGenericReturnType();
if (type instanceof ParameterizedType) {
    return getGenericClass(source, (ParameterizedType) type);
} else {
    return method.getReturnType();
ListgetMethods(Class objectClass, Class annotationClass)
get Methods
List<Method> methods = new ArrayList<Method>();
getMethods(objectClass, annotationClass, methods);
return methods;
ListgetMethods(Object instance, String name, Class[] arguments, boolean isPrefix)
Returns setters of given instance with given argumentType
Method[] methods = instance.getClass().getMethods();
ArrayList<Method> collect = new ArrayList<Method>(methods.length);
compliance: for (int m = 0; m < methods.length; m++) {
    Method method = methods[m];
    if (!method.getName().matches(name))
        continue;
    if (!Modifier.isPublic(method.getModifiers()))
        continue;
...
Method[]getMethods(Object obj, boolean hasParent)
get Methods
if (isEmpty(obj)) {
    return null;
if (hasParent)
    return obj.getClass().getMethods();
return obj.getClass().getDeclaredMethods();
Method[]getMethods(Object obj, int cmpModifier, String prefix)
get Methods
Method[] retMethod = null;
Class<?> objClass = obj.getClass();
Method[] methods = objClass.getDeclaredMethods();
if (methods != null && !(methods.length < 1)) {
    int j = 0;
    for (int i = 0; i < methods.length; i++) {
        int modifier = methods[i].getModifiers();
        if (prefix != null && !prefix.equals("")) {
...