Invoke a method by its name.
If more than one method exists in {@code targetClass}, the first method with the right
number of arguments will be used, and later calls will all use that method.
checkNotNull(methodName, "methodName must not be null");
Method targetMethod = mMethods.get(methodName);
if (targetMethod == null) {
for (Method method : mTargetClass.getMethods()) {
// TODO future: match types of params if possible
if (method.getName().equals(methodName) &&
(params.length == method.getParameterTypes().length) ) {
targetMethod = method;
mMethods.put(methodName, targetMethod);
break;
}
}
if (targetMethod == null) {
throw new IllegalArgumentException(
"Method " + methodName + " does not exist on class " + mTargetClass);
}
}
try {
return (K) mTarget.dispatch(targetMethod, params);
} catch (Throwable e) {
UncheckedThrow.throwAnyException(e);
// unreachable
return null;
}