强制在编译时Java注释 [英] Enforcing java annotations at compile time

查看:611
本文介绍了强制在编译时Java注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:我想,以确保此注解是在一类编译时present。这可能吗 ?我认识到,annoataions自身是班,所以我想这样的 - 但是我的班我只是不知道语法哪里以及如何执行/实现这样的结构。

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.

推荐答案

您可以写注释处理器在编译时运行任意的逻辑。

You can write an annotation processor to run arbitrary logic at compile time.

从注​​释处理器,你可以做这样的事情检查类是否具有特定结构或成员present如果该类存在一个特定的注释。他们是pretty灵活的 - 更多的,你可以跟他们做哪些检查出了一个主意<一的href=\"http://docs.oracle.com/javase/6/docs/api/javax/annotation/processing/AbstractProcessor.html\">the API 。他们还支持主要IDE,比如Eclipse和Netbeans。

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. They are also supported in major IDEs such as Eclipse and Netbeans.

编写注释处理器的介绍是<一个href=\"http://today.java.net/pub/a/today/2008/04/10/source-$c$c-analysis-using-java-6-compiler-apis.html\">here.

An introduction to writing an annotation processor is here.

这篇关于强制在编译时Java注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆