/** * Finds a method by name and parameter types. * * @param declaringType the name of the class * @param methodName the name of the method to look for * @param parameterTypes the types of the parameters */ public static Method getMethod(Class<?> declaringType, String methodName, Class<?>... parameterTypes) { return findMethod(declaringType, methodName, parameterTypes); } }
/** * Finds a method by name and parameter types. * * @param declaringType the name of the class * @param methodName the name of the method to look for * @param parameterTypes the types of the parameters */ public static Method getMethod(Class<?> declaringType, String methodName, Class<?>... parameterTypes) { return findMethod(declaringType, methodName, parameterTypes); } }
public static Object invoke(Object target, String methodName, Object[] args) { try { Class<? extends Object> clazz = target.getClass(); Method method = findMethod(clazz, methodName, args); method.setAccessible(true); return method.invoke(target, args); } catch (Exception e) { throw LOG.exceptionWhileInvokingMethod(methodName, target, e); } }
public static Object invoke(Object target, String methodName, Object[] args) { try { Class<? extends Object> clazz = target.getClass(); Method method = findMethod(clazz, methodName, args); method.setAccessible(true); return method.invoke(target, args); } catch (Exception e) { throw LOG.exceptionWhileInvokingMethod(methodName, target, e); } }
private static Method findMethod(Class< ? extends Object> clazz, String methodName, Object[] args) { for (Method method : clazz.getDeclaredMethods()) { // TODO add parameter matching if ( method.getName().equals(methodName) && matches(method.getParameterTypes(), args) ) { return method; } } Class< ? > superClass = clazz.getSuperclass(); if (superClass!=null) { return findMethod(superClass, methodName, args); } return null; }
private static Method findMethod(Class< ? extends Object> clazz, String methodName, Object[] args) { for (Method method : clazz.getDeclaredMethods()) { // TODO add parameter matching if ( method.getName().equals(methodName) && matches(method.getParameterTypes(), args) ) { return method; } } Class< ? > superClass = clazz.getSuperclass(); if (superClass!=null) { return findMethod(superClass, methodName, args); } return null; }
/** * Finds a method by name and parameter types. * * @param declaringType the name of the class * @param methodName the name of the method to look for * @param parameterTypes the types of the parameters */ public static Method getMethod(Class<?> declaringType, String methodName, Class<?>... parameterTypes) { return findMethod(declaringType, methodName, parameterTypes); } }
public static Object invoke(Object target, String methodName, Object[] args) { try { Class<? extends Object> clazz = target.getClass(); Method method = findMethod(clazz, methodName, args); method.setAccessible(true); return method.invoke(target, args); } catch (Exception e) { throw LOG.exceptionWhileInvokingMethod(methodName, target, e); } }
private static Method findMethod(Class< ? extends Object> clazz, String methodName, Object[] args) { for (Method method : clazz.getDeclaredMethods()) { // TODO add parameter matching if ( method.getName().equals(methodName) && matches(method.getParameterTypes(), args) ) { return method; } } Class< ? > superClass = clazz.getSuperclass(); if (superClass!=null) { return findMethod(superClass, methodName, args); } return null; }