10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.6 Annotation Types INTERFACES<br />

276<br />

DISCUSSION<br />

<strong>The</strong> convention is illustrated in the following annotation type declaration:<br />

// Single-element annotation type declaration<br />

/**<br />

* Associates a copyright notice with the annotated API element.<br />

*/<br />

public @interface Copyright {<br />

String value();<br />

}<br />

<strong>The</strong> following annotation type declaration defines a single-element annotation type whose<br />

sole element has an array type:<br />

// Single-element annotation type declaration with array-typed<br />

// element<br />

/**<br />

* Associates a list of endorsers with the annotated class.<br />

*/<br />

public @interface Endorsers {<br />

String[] value();<br />

}<br />

Here is an example of complex annotation types, annotation types that contain one or more<br />

elements whose types are also annotation types.<br />

// Complex Annotation Type<br />

/**<br />

* A person’s name. This annotation type is not designed to be used<br />

* directly to annotate program elements, but to define elements<br />

* of other annotation types.<br />

*/<br />

public @interface Name {<br />

String first();<br />

String last();<br />

}<br />

DRAFT<br />

/**<br />

* Indicates the author of the annotated program element.<br />

*/<br />

public @interface Author {<br />

Name value();<br />

}<br />

/**<br />

* Indicates the reviewer of the annotated program element.<br />

*/<br />

public @interface Reviewer {<br />

Name value();<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!