我在与比我自己缺乏更有效地做到这一点的能力以外,没有理由对我的代码加倍麻烦的反射和注解......帮助在Java
for (Method curr: all){
if (curr.isAnnotationPresent(anno)){
if (anno == Pre.class){
for (String str : curr.getAnnotation(Pre.class).value()){
if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
toRun.add(curr);
}
}
} if (anno == Post.class) {
for (String str : curr.getAnnotation(Post.class).value()){
if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
toRun.add(curr);
}
}
}
}
}
阿鲁是一个参数 - Class<? extends Annotation>
和Pre
和Post
是我的注释,都有一个value()
这是一个字符串数组。
当然,这都是因为我让Eclipse自动填充代码,我还不明白。
如果'anno'既不是,也不是'toRun'类型? – 2010-05-30 17:56:40
尝试消除冗余(在条件表达式中)。 – 2010-05-30 18:01:36