提交 5c25ab84 编写于 作者: C cherrylzhao

#1363 Refactor methodInvoke.

上级 be4e5553
......@@ -94,16 +94,7 @@ public final class ReflectiveUtil {
*/
@SneakyThrows
public static Object methodInvoke(final Object target, final String methodName, final Object... args) {
Method method;
if (null != args) {
Class<?>[] parameterTypes = new Class[args.length];
for (int i = 0; i < args.length; i++) {
Array.set(parameterTypes, i, args[i].getClass());
}
method = getMethod(target, methodName, parameterTypes);
} else {
method = getMethod(target, methodName);
}
Method method = getMethod(target, methodName, getParameterTypes(args));
Preconditions.checkNotNull(method);
method.setAccessible(true);
try {
......@@ -113,6 +104,17 @@ public final class ReflectiveUtil {
}
}
private static Class<?>[] getParameterTypes(final Object[] args) {
if (null == args) {
return null;
}
Class<?>[] result = new Class[args.length];
for (int i = 0; i < args.length; i++) {
Array.set(result, i, args[i].getClass());
}
return result;
}
@SneakyThrows
@SuppressWarnings("unchecked")
private static Method getMethod(final Object target, final String methodName, final Class<?>... parameterTypes) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册