List of utility methods to do Reflection Method Name
Method | getMethod(final String methodName, final Class> objClass, final Class>[] paramClasses) get Method if (objClass == Object.class) { return objClass.getDeclaredMethod(methodName, paramClasses); try { return objClass.getDeclaredMethod(methodName, paramClasses); } catch (final NoSuchMethodException e) { return getMethod(methodName, objClass.getSuperclass(), paramClasses); |
Method | getMethod(int requireMod, int bannedMod, Class> clazz, String methodName, Class>... params) Search for the first publically and privately defined method of the given name and parameter count. for (Method method : clazz.getDeclaredMethods()) { if ((method.getModifiers() & requireMod) == requireMod && (method.getModifiers() & bannedMod) == 0 && (methodName == null || method.getName().equals(methodName)) && Arrays.equals(method.getParameterTypes(), params)) { method.setAccessible(true); return method; if (clazz.getSuperclass() != null) { return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params); throw new IllegalStateException( String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); |
Method | getMethod(Method[] methods, String name) get Method Method method = null; for (int i = 0; i < methods.length; i++) { method = methods[i]; if (!Modifier.isPublic(method.getModifiers())) continue; if (method.getName().equals(name)) return method; return null; |
Method | getMethod(Method[] methods, String name, Class[] params) Returns the method matching the name. Method method = null; loop: for (int i = 0; i < methods.length; i++) { method = methods[i]; if (!Modifier.isPublic(method.getModifiers())) continue; if (!Modifier.isPublic(method.getDeclaringClass().getModifiers())) continue; if (!method.getName().equals(name)) ... |
String[] | getMethod(String className) get Method Class<?> classz = Class.forName(className); Method[] methods = classz.getMethods(); Set<String> set = new HashSet<>(); for (Method f : methods) { set.add(f.getName()); return set.toArray(new String[set.size()]); |
Method | getMethod(String className, String functionName, Class[] paramTypes) get Method Method method = null;
Class actionClassObj;
actionClassObj = Class.forName(className);
method = actionClassObj.getMethod(functionName, paramTypes);
return method;
|
Method | getMethod(String className, String functionName, Class[] paramTypes) get Method Method method = null;
Class actionClassObj;
actionClassObj = Class.forName(className);
method = actionClassObj.getMethod(functionName, paramTypes);
return method;
|
Method | getMethod(String className, String methodName, Class>[] params) get Method Class<?> clazz = Class.forName(className);
return clazz.getMethod(methodName, params);
|
Method | getMethod(String methodName, Class> clazz) get Method Method method = getDeclaredMethod(methodName, clazz); if (method == null) { Class<?> parent = clazz.getSuperclass(); while (parent != null) { method = getDeclaredMethod(methodName, parent); if (method != null) break; parent = parent.getSuperclass(); ... |
Method | getMethod(String methodName, Class> clazz, Class>... args) get Method Method method; try { method = clazz.getMethod(methodName, args); } catch (NoSuchMethodException e1) { method = null; return method; |