求指教,java反射去Annotation

imwy1029 imwy1029 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题:
##自定义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;
为什么?
...全文
评论
收藏 已收藏
分享
返回顶部
imwy1029
非技术区 23,404 成员 70,505 内容