Java注释处理:可以访问非注释类的“元素”吗?
Java 注释处理(自 Java 6 起)是一个非常好的概念,因为它允许通过 Element
接口(以及其他接口)访问有关类和方法的大量信息。
但遗憾的是,我必须凭经验发现,未注释的类永远不会传递给自定义注释处理器:
warning: No SupportedAnnotationTypes annotation found on
my.TESTProcessor, returning an empty set.
我的发现是真的吗?或者我可以“欺骗”编译器来为我的自定义注释处理器提供有关非注释类的信息吗?
Java annotation processing (since Java 6) is a very good concept, because it allows to access lots of information about classes and methods through the Element
interface (and others).
But sadly, I had to find out empirically, that non-annotated classes are never passed to a custom annotation processor:
warning: No SupportedAnnotationTypes annotation found on
my.TESTProcessor, returning an empty set.
Are my findings true? Or can I "trick" the compiler to give my custom annotation processor information about non-annotated classes as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
伟大的!
这给了我真正的所有类,而不仅仅是带注释的类:
该注释的规范说:
经过测试,有效!
Great!
This gives me really all classes, not just annotated ones:
The spec of that anotation says:
Tested, works!