Datasheet
AnnotationTypeElementDoc
This interface represents an element of an annotation type.
Method Description
AnnotationValue Returns the default value associated with this annotation type, or null if
defaultValue() there is no default value.
AnnotationValue
This interface represents the value of an annotation type element.
Method Description
String toString() Returns a string representation of the value.
Object value() Returns the value. The object behind this value could be any of the
following.
❑ A wrapper class for a primitive type (such as
Integer or Float)
❑ A
String
❑ A Type (representing a class, a generic class, a type variable, a wildcard
type, or a primitive data type)
❑ A
FieldDoc (representing an enum constant)
❑ An
AnnotationDesc
❑ An array of AnnotationValue
Here’s an example using the annotation support provided by the doclet API. This doclet echoes all anno-
tations and their values that it finds in a source file:
import com.sun.javadoc.*;
import java.lang.annotation.*;
public class AnnotationViewer {
public static boolean start(RootDoc root)
{
ClassDoc[] classes = root.classes();
for (ClassDoc cls : classes) {
showAnnotations(cls);
}
return(true);
}
static void showAnnotations(ClassDoc cls)
{
System.out.println(“Annotations for class [“ + cls + “]”);
30
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 30