我开始了“为了好玩,没人知道,没有人关心”开源项目(LinkSet)。有没有一种更有效的方法来获得注释的方法?
在一个地方,我需要得到一个类的注释方法。
有没有比这更有效的方法呢?我的意思是不需要遍历每种方法?
for (final Method method : cls.getDeclaredMethods()) {
final HandlerMethod handler = method.getAnnotation(HandlerMethod.class);
if (handler != null) {
return method;
}
}
如果你只是想知道,如果该方法具有注释和不关心注释的内容,你可以调用'method.isAnnotationPresent(HandlerMethod.class)' – 2010-02-10 14:26:21