Java Reference
In-Depth Information
Listing 1-14. A Repeatable Annotation Type That Uses the ChangeLogs as the Containing Annotation Type
// ChangeLog.java
package com.jdojo.annotation;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(ChangeLogs.class)
public @interface ChangeLog {
String date();
String comments();
}
Listing 1-15. A Contaning Annotation Type for the ChangeLog Repeatable Annotation Type
// ChangeLogs.java
package com.jdojo.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface ChangeLogs {
ChangeLog[] value();
}
You can use the ChangeLog annotation to log change history for the Test class, as shown:
@ChangeLog(date="02/01/2014", comments="Declared the class")
@ChangeLog(date="02/21/2014", comments="Added the process() method")
public class Test {
public static void process() {
// Code goes here
}
}
The Native Annotation
The Native annotation type is a meta-annotation that is used to annotate fields. It indicates that the annotated field
may be referenced from native code. It is a marker annotation. Typically, it is used by tools that generate some code
based on this annotation.
 
Search WWH ::




Custom Search