Interface AnnotationTarget

All Known Subinterfaces:
ArrayType, ClassInfo, ClassType, DeclarationInfo, FieldInfo, MethodInfo, PackageInfo, ParameterInfo, ParameterizedType, PrimitiveType, RecordComponentInfo, Type, TypeVariable, VoidType, WildcardType

public interface AnnotationTarget
An annotation target is anything that can be annotated. That is:
  • a declaration, such as a class, a method, a field, etc.
  • a type, such as the type of a method parameter, the type of a field, a type argument, a type parameter, present in a declaration of a generic class or method, etc.
The hasAnnotation, annotation, repeatableAnnotation and annotations methods may be used to obtain information about annotations present on this annotation target. The phrase "present on this annotation target" means: either the annotation is declared or implicitly declared directly on this annotation target, or this annotation target is a class declaration and the annotation is inherited from a superclass.

Note that if more than one annotation of a repeatable annotation type is declared on an annotation target, only an implicitly declared container annotation is present on the annotation target; the originally declared annotations are not. If exactly one annotation of a repeatable annotation type is declared on an annotation target, that annotation is present.

Annotations are represented as AnnotationInfo, so that implementations of this interface are not required to instantiate the annotation type.

Implementations of this interface are required to define the equals and hashCode methods. Implementations of this interface are encouraged to define the toString method such that it returns a text resembling the corresponding Java™ syntax.

There is no guarantee that any particular construct, represented by an implementation of this interface, will always be represented by the same object. That includes natural singletons such as the java.lang.Object class declaration, or the void pseudo-type. Instances should always be compared using equals.

Since:
4.0