CHAPTER 9 SCRIPTING AND JSR 223 181
Pluggable Annotation Processing Updates CHAPTER 10 Are you apt to use the apt tool? Annotations are a concept introduced with the 5.0 release of J2SE and JSR 175. In this chapter, you ll explore those annotations added to Java SE 6. Although this is a Java 6 book, since annotations are so new, it is best to start with a description of what exactly they are and how to use them, and not just focus on the new ones. Confused yet? First, apt stands for the annotation processing tool. It is a new command-line tool that comes with the JDK. (Well, it was new for the 5.0 release.) You use annotations to annotate your source code, and apt to make new annotations. Annotations are @ tags that appear in source, not javadoc-style comments. They have corresponding classes in the system, either as part of the core libraries or created by you. For instance, the @deprecated javadoc tag can be thought of as an annotation, although it isn t exactly. It acts as metadata that affects how tools and libraries interact with your classes. The @deprecated tag tells the compiler to generate a compilation warning when you use the method or class. Before digging too deeply into annotations, though, it is important to repeat a line from the Java documentation: Typical application programmers will never have to define an annotation type (see http://java.sun.com/j2se/1.5.0/docs/guide/language/ annotations.html). However, defining annotations is different than using them. So, let s look at using a few first. Before going into the specifics of what to do with annotations, here s what an annotation declaration looks like: package java.lang; import java.lang.annotation.*; @Documented @Retention(RetentionPolicy.RUNTIME) public @interface Deprecated { } 183
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services