简体   繁体   English

在编译时执行java注释

[英]Enforcing java annotations at compile time

Hi : I wanted to make sure that an annotation is present at compile time in a class. 嗨:我想确保在编译时在类中存在注释。 Is this possible ? 这可能吗 ? I realize that annoataions are, themselves, classes, so I assume so - but Im just not sure syntactically where and how to enforce/implement such a structure in my classes. 我知道annoataions本身就是类,所以我假设 - 但我不确定语法在哪里以及如何在我的类中强制/实现这样的结构。

You can write an annotation processor to run arbitrary logic at compile time. 您可以编写注释处理器以在编译时运行任意逻辑。

From an annotation processor, you can do things like check whether a class has a particular structure or member present if a particular annotation exists on that class. 从注释处理器中,如果该类上存在特定注释,则可以执行诸如检查类是否具有特定结构或成员的事情。 They are pretty flexible - for more of an idea of what you can do with them check out the API . 它们非常灵活 - 有关您可以使用它们做什么的更多信息,请查看API They are also supported in major IDEs such as Eclipse and Netbeans. Eclipse和Netbeans等主要IDE也支持它们。

An introduction to writing an annotation processor is here . 这里是编写注释处理器的介绍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM