Skip to content

Commit

Permalink
Minor - remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Oct 11, 2012
1 parent 5290a22 commit 114012b
Showing 1 changed file with 7 additions and 19 deletions.
Expand Up @@ -308,25 +308,13 @@ protected T work() throws Exception {
* method
* @see java.lang.reflect.Method#invoke(Object, Object...)
*/
public static <T> T invoke(final Object instance, final String methodName, final Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
return new SecureReflectionAccess<T>() {
@Override
protected T work() throws Exception {
Class<?>[] parameterTypes = new Class<?>[parameters.length];
for (int i = 0; i < parameters.length; i++) {
parameterTypes[i] = parameters[i].getClass();
}
Method method = getMethod(instance.getClass(), methodName, parameterTypes);

Object result = ensureAccessible(method).invoke(instance, parameters);

@SuppressWarnings("unchecked")
T t = (T) result;

return t;

}
}.runAsInvocation();
public static <T> T invoke(final Object instance, final String methodName, final Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Class<?>[] parameterTypes = new Class<?>[parameters.length];
for (int i = 0; i < parameters.length; i++) {
parameterTypes[i] = parameters[i].getClass();
}
Method method = getMethod(instance.getClass(), methodName, parameterTypes);
return invoke(instance, method, parameters);
}

/**
Expand Down

0 comments on commit 114012b

Please sign in to comment.