求指教,java反射去Annotation

imwy1029 2012-03-30 03:16:50
如题:
##自定义Annotation##
public @interface MyAnnotation {
String role();
}

##Users类##
public class User {
@MyAnnotation(role="aaa")
public void say()
{
System.out.println("HI!");
}
}

##Main方法##
Class a=Class.forName("Users");
Method [] method=a.getMethods();
for (int i = 0; i < method.length; i++) {
System.out.println(method[i].getName());
System.out.println(method[i].getAnnotations().length);
}


结果Say方法为的Annotations为0;
为什么?
...全文
21 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧