如何获取被指定Annotation注释的所有类
答案:2 悬赏:20
解决时间 2021-11-13 04:39
- 提问者网友:放荡不羁
- 2021-11-12 21:12
如何获取被指定Annotation注释的所有类
最佳答案
- 二级知识专家网友:闲懒诗人
- 2021-11-12 21:58
只有被指定为@Retention(RetentionPolicy.RUNTIME)的才可以用反射的方式获取。
@NewAnnotationType
public class NewClass {
public void DoSomething() {}
}
获取注解:
Class newClass = NewClass.class;
for (Annotation annotation : newClass.getDeclaredAnnotations()) {
System.out.println(annotation.toString());
}
@NewAnnotationType
public class NewClass {
public void DoSomething() {}
}
获取注解:
Class newClass = NewClass.class;
for (Annotation annotation : newClass.getDeclaredAnnotations()) {
System.out.println(annotation.toString());
}
全部回答
- 1楼网友:野性且迷人
- 2021-11-12 22:56
annotation 对象处于图形窗口中一个单独的层,该层的父对象是figure,所以对axes层的操作(例如cla)不会对annotation有任何影响。
可以用下面的命令删除当前窗口中所有的annotation对象:
delete(getappdata(gcf,'scribe_scribeoverlay'))这种方法本质上是删除整个annotation层,而不是单独删除某个annotation对象。要想单独删除某个(或某些)特定的annotation对象,并没有太好的获取annotation对象句柄的方法。如果annotation是用鼠标添加的,就应该手动删除;如果是用命令创建的,请在创建时返回其句柄,并自行维护一个句柄列表。
上面提到的方法未载入文档,属于未公开的内容,所以不保证在所有版本上都适用。我是分析matlab代码找到这种方法的,用百度和bing搜了一下,还未见有其他人提到过。
希望对楼主有帮助。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯