ReflectionUtils中的doWithMethods()方法处理逻辑不那么优雅..
- Dominant language
- Java
- Stars
- 525
- Forks
- 115
- PR merge metrics
- No merged PRs in 30d
Description
背景:
1. ~~我们是个代码洁癖爱好者~~
2.该方法既然是个通用的工具方法,那么当我们的clazz是个接口时,此时实现逻辑会有那么一点尴尬(同一个方法会重复callback)~~
//步骤1.getDeclaredMethods(clazz)方法功能其实是已经去clazz继承的接口中拿了一下default以及static类型的方法。
Method[] methods = getDeclaredMethods(clazz);
for (Method method : methods) {
XXX
}if (clazz.getSuperclass() != null) {
doWithMethods(clazz.getSuperclass(), mc, mf);
}
//此时由于clazz是个接口,会走到这里
else if (clazz.isInterface()) {
//此时又去拿clazz接口继承的接口了,然后递归doWithMethods()时一定又会拿到上面"步骤1中继承的接口中已经拿到过的default和static方法",也就是说重复callback了
for (Class superIfc : clazz.getInterfaces()) {
doWithMethods(superIfc, mc, mf);
}
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.