We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
单元测试测试一个私有方法 方法签名如下所示:
private List<Bar> getBarList(List<Foo> fooList, Long Id)
刚开始直接调用
ReflectionUtil.invokeMethod(obj, "getBarList", fooList, 1L);
报错: java.lang.IllegalArgumentException: Could not find method [getBarList] on target [XXX] 断点调试发现实际参数类型用的是ArrayList
java.lang.IllegalArgumentException: Could not find method [getBarList] on target [XXX]
ArrayList
于是显式指定方法参数类型
ReflectionUtil.invokeMethod(obj, "getBarList", new Object[]{ fooList, 1L}, new Class[]{List.class,Long.class});
还是不行 断点调试发现下面的代码将Long.class --> long
Long.class --> long
// 处理原子类型与对象类型的兼容 ClassUtil.wrapClassses(theParameterTypes);
最后只好使用下面的写法解决了该问题
ReflectionUtil.invokeMethodByName(obj, "getBarList", new Object[]{ fooList, 1L});
我觉得如果调用者显式指定了参数类型 如下所示 直接使用好了 不用多做额外的处理了吧 如包装类型 --> 基本类型
The text was updated successfully, but these errors were encountered:
谢谢反馈,我看看
Sorry, something went wrong.
已修复,多用Apache Commmon Lang里的类
No branches or pull requests
ReflectionUtil 使用反馈
单元测试测试一个私有方法 方法签名如下所示:
刚开始直接调用
报错:
java.lang.IllegalArgumentException: Could not find method [getBarList] on target [XXX]
断点调试发现实际参数类型用的是
ArrayList
于是显式指定方法参数类型
还是不行
断点调试发现下面的代码将
Long.class --> long
最后只好使用下面的写法解决了该问题
反馈
我觉得如果调用者显式指定了参数类型 如下所示 直接使用好了 不用多做额外的处理了吧 如包装类型 --> 基本类型
The text was updated successfully, but these errors were encountered: