[b]Java Annotation Purposes[/b]
[color=green]Java annotations are typically used for the following purposes:[/color]
·Compiler instructions
·Build-time instructions
·Runtime instructions
Java has 3 built-in annotations that you can use to give instructions to the Java compiler. These annotations are explained in more detail later in this text.
Java annotations can be be used at build-time, when you build your software project. The build process includes generating source code, compiling the source, generating XML files (e.g. deployment descriptors), packaging the compiled code and files into a JAR file etc. Building the software is typically done by an automatic build tool like Apache Ant or Apache Maven. Build tools may scan your Java code for specific annotations and generate source code or other files based on these annotations.
Normally, Java annotations are not present in your Java code after compilation. It is possible, however, to define your own annotations that are available at runtime. These annotations can then be accessed via Java Reflection, and used to give instructions to your program, or some third party API.
[url]http://tutorials.jenkov.com/java/annotations.html[/url]
知道了annotation的目地, 那么, annotation是如何运作的呢(虽然别人定义好了,只需用就可以了)?
答案:借助reflection
[url]http://tutorials.jenkov.com/java-reflection/annotations.html[/url]
-
[color=green]Java annotations are typically used for the following purposes:[/color]
·Compiler instructions
·Build-time instructions
·Runtime instructions
Java has 3 built-in annotations that you can use to give instructions to the Java compiler. These annotations are explained in more detail later in this text.
Java annotations can be be used at build-time, when you build your software project. The build process includes generating source code, compiling the source, generating XML files (e.g. deployment descriptors), packaging the compiled code and files into a JAR file etc. Building the software is typically done by an automatic build tool like Apache Ant or Apache Maven. Build tools may scan your Java code for specific annotations and generate source code or other files based on these annotations.
Normally, Java annotations are not present in your Java code after compilation. It is possible, however, to define your own annotations that are available at runtime. These annotations can then be accessed via Java Reflection, and used to give instructions to your program, or some third party API.
[url]http://tutorials.jenkov.com/java/annotations.html[/url]
知道了annotation的目地, 那么, annotation是如何运作的呢(虽然别人定义好了,只需用就可以了)?
答案:借助reflection
[url]http://tutorials.jenkov.com/java-reflection/annotations.html[/url]
-
本文介绍了Java注解的主要用途,包括编译器指令、构建时指令和运行时指令。此外还探讨了内置注解如何用于指导Java编译器,并解释了自定义注解如何在构建过程及运行时发挥作用。
994

被折叠的 条评论
为什么被折叠?



