List of utility methods to do Reflection Method Parameter
Method | getMethod(Class> clazz, String name, Class>[] parameterTypes) Returns a matching method for the given name and parameters on the given class If the parameterTypes arguments is null it will return the first matching method on the class. return getMethod(clazz, name, parameterTypes, false);
|
java.lang.reflect.Method | getMethod(Class> cls, String name, Class>... parameterTypes) get Method try { return cls.getMethod(name, parameterTypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); |
Method | getMethod(Class> clz, String methodName, Class>... parameterTypes) get Method try { Method m = clz.getDeclaredMethod(methodName, parameterTypes); return m; } catch (NoSuchMethodException | SecurityException e) { return getMethodByNameSimple(clz, methodName); |
Method | getMethod(Class> declaringClass, String name, Class>... parameterTypes) get Method try { if (parameterTypes == null) { Method found = null; for (Method m : declaringClass.getDeclaredMethods()) { if (m.getName().equals(name)) { if (found != null) { throw new RuntimeException( "more than one method named " + name + " in " + declaringClass); ... |
Method | getMethod(Class> declaringType, String methodName, Class>... parameterTypes) Finds a method by name and parameter types. return findMethod(declaringType, methodName, parameterTypes);
|
Method | getMethod(Class> instance, String method, Class>... parameters) get Method if (instance != null && method != null) { try { return instance.getMethod(method, parameters); } catch (Exception e) { e.printStackTrace(); return null; ... |
Method | getMethod(Class> sourceClass, boolean isFindDeclaredMethod, boolean isUpwardFind, String methodName, Class>... methodParameterTypes) get Method Method method = null; try { method = isFindDeclaredMethod ? sourceClass.getDeclaredMethod(methodName, methodParameterTypes) : sourceClass.getMethod(methodName, methodParameterTypes); } catch (NoSuchMethodException e1) { if (isUpwardFind) { Class<?> classs = sourceClass.getSuperclass(); while (method == null && classs != null) { ... |
Method | getMethod(Class> target, String methodName, Class>... parameterTypes) get Method try { Method m = target.getDeclaredMethod(methodName, parameterTypes); if (m != null) { return m; } else { return target.equals(Object.class) ? null : getMethod(target.getSuperclass(), methodName, parameterTypes); } catch (Exception e) { return target.equals(Object.class) ? null : getMethod(target.getSuperclass(), methodName, parameterTypes); |
Method | getMethod(Class> type, String name, Class>... parametersType) Retrieve a method from a given class or one of its superclass. try { return type.getMethod(name, parametersType); } catch (NoSuchMethodException e) { if (!Object.class.equals(type.getSuperclass())) { return getMethod(type.getSuperclass(), name, parametersType); throw new NoSuchMethodException(); |
Method | getMethod(Class> type, String name, Class>... parameterTypes) get Method try { return myGetMethod(type, name, parameterTypes); } catch (NoSuchMethodException e) { throw new RuntimeException(e); |