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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9.6 Annotation Types INTERFACES<br />

274<br />

It is a compile-time error if an annotation type T contains an element of type<br />

T, either directly or indirectly.<br />

DISCUSSION<br />

For example, this is illegal:<br />

// Illegal self-reference!!<br />

@interface SelfRef {<br />

SelfRef value();<br />

}<br />

and so is this:<br />

// Illegal circularity!!<br />

@interface Ping {<br />

Pong value();<br />

}<br />

@interface Pong {<br />

Ping value();<br />

}<br />

Note also that this specification precludes elements whose types are nested arrays. For<br />

example, this annotation type declaration is illegal:<br />

// Illegal nested array!!<br />

@interface Verboten {<br />

String[][] value();<br />

}<br />

An annotation type element may have a default value specified for it. This is<br />

done by following its (empty) parameter list with the keyword default and the<br />

default value of the element.<br />

Defaults are applied dynamically at the time annotations are read; default values<br />

are not compiled into annotations. Thus, changing a default value affects<br />

annotations even in classes that were compiled before the change was made (presuming<br />

these annotations lack an explicit value for the defaulted element).<br />

An ElementValue is used to specify a default value. It is a compile-time error<br />

if the type of the element is not commensurate (§9.7) with the default value specified.<br />

An ElementValue is always FP-strict (§15.4).<br />

DRAFT

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

Saved successfully!

Ooh no, something went wrong!