public Builder methodSignature(String name, Class<?>... args) {
Class objectClass = mTarget.getClass();
if(objectClass == Object.class) return this;
// build signature by object , name & args
do {
try {
// bug here
targetMethod = (Method) mFindMethod.invoke(objectClass, name, args);
return this;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
objectClass = objectClass.getSuperclass();
} while (mResoveParent && objectClass != Object.class);
return this;
}
问题: 可边长参数 args , 作为参数传入 invoke 方法后,会作为 invoke 方法的可变长参数的第一个参数传递。
相当于传入了 Object nArgs[]
nArgs[0] = args;
解决办法:
Object vars[] = args;
targetMethod = (Method) mFindMethod.invoke(objectClass, name, vars);
来源:oschina
链接:https://my.oschina.net/u/592116/blog/4306732