List of utility methods to do Reflection Method Parameter
Optional | getMethod(Class> type, String name, Class>... parameterTypes) get Method try { return Optional.of(type.getDeclaredMethod(name, parameterTypes)); } catch (NoSuchMethodException e) { return Optional.empty(); |
Method | getMethod(Class This method return the list of method of any class. Method method = null; try { method = clazz.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { if (methodName.startsWith("get")) { methodName = methodName.replaceFirst("get", "is"); } else if (methodName.startsWith("is")) { methodName = methodName.replaceFirst("get", "is"); ... |
Method | getMethod(final Class clazz, final String name, final Class>... parameterTypes) get Method if (clazz == null) { throw new NoSuchMethodException(name + "() method not found."); try { return clazz.getDeclaredMethod(name, parameterTypes); } catch (Exception ex) { return getMethod(clazz.getSuperclass(), name, parameterTypes); |
Method | getMethod(final Class javaClass, final String methodName, final Class[] methodParameterTypes, final boolean shouldSetAccessible) Get a method declared in the given class. Method method = findMethod(javaClass, methodName, methodParameterTypes); if (shouldSetAccessible) { method.setAccessible(true); return method; |
Method | getMethod(final Class> aClass, final String methodName, Class>[] parameterTypes) Warning : each call of this method should be tested with a JUnit test, in order to know when the API has changed Method m = null;
m = aClass.getDeclaredMethod(methodName, parameterTypes);
m.setAccessible(true);
return m;
|
Method | getMethod(final Class> clazz, final String methodName, final Class>... parameterTypes) get Method try { return clazz.getDeclaredMethod(methodName, parameterTypes); } catch (final NoSuchMethodException ex) { return null; |
Method | getMethod(final Class> clazz, final String name, final Class>... parametertypes) Get a method by name. Method result = null; for (final Method method : getMethods(clazz)) { if (method.getName().equals(name) && Arrays.equals(method.getParameterTypes(), parametertypes)) { result = method; break; if (result == null) ... |
Method | getMethod(final Class> clazz, final String name, final Class>... parameterTypes) Returns the matched public method of the specified class or null if no such method try { return clazz.getMethod(name, parameterTypes); } catch (final Exception e) { return null; |
Method | getMethod(final Class> target, final String name, final Class>... parameters) Gets the method defined on the target class. final String key = target.getName() + '.' + name; Method method = METHOD_CACHE.get(key); if (method != null) { return method; try { method = target.getMethod(name, parameters); METHOD_CACHE.put(key, method); ... |
Method | getMethod(final Class get Method try { return receiver.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); |