List of utility methods to do Reflection Method Get from Object
Set | getMethodNames(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(); ... |
Object | getMethodObject(Class extends T> 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);
|
Object | getMethodObject(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 { ... |
Object | getMethodResult(final Object element, final String methodName) get Method Result return getMethodResult(element, methodName, null);
|
Object | getMethodReturn(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); |
Class | getMethodReturnTypeGeneric(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(); |
List | getMethods(Class> objectClass, Class extends Annotation> annotationClass) get Methods List<Method> methods = new ArrayList<Method>(); getMethods(objectClass, annotationClass, methods); return methods; |
List | getMethods(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("")) { ... |