-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
背景:
我们是个代码洁癖爱好者
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);
}
}
Metadata
Metadata
Assignees
Labels
No labels