Java Reference
In-Depth Information
kind of declaration
public Card[] deal(@Stub("5,12/21/2012,unassigned") int
cards)
^
3 errors
Thesecondproblemisthatthedefault
CLASS
retentionpolicymakesitimpossibleto
process
@Stub
annotationsatruntime.Youcanfixthisproblembyprefixingthe
Stub
type declaration with
@Retention(RetentionPolicy.RUNTIME)
.
@Retention
meta-annotations.
Listing 3-48.
A revamped
Stub
annotation type
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
public @interface Stub
{
String value();
}
Note
Javaalsoprovides
Documented
and
Inherited
meta-annotationtypesin
the
java.lang.annotation
package.Instancesof
@Documented
-annotatedan-
notationtypesaretobedocumentedby
javadoc
andsimilartools,whereasinstances
of
@Inherited
-annotatedannotationtypesareautomaticallyinherited.Accordingto
Inherited
'sJavadocumentation,if“theuserqueriestheannotationtypeonaclass
declaration, and the class declaration has no annotation for this type, then the class's
superclass will automatically be queried for the annotation type. This process will be
repeateduntilanannotationforthistypeisfound,orthetopoftheclasshierarchy(
Ob-
ject
)isreached.Ifnosuperclasshasanannotationforthistype,thenthequerywill
indicate that the class in question has no such annotation.”