As, I know we can apply annotation like @Target
, @Retention
, @Documented
on custom annotation.
But recently I saw @Constraint applied on custom annotation.
Can We use any annotation on custom annotation? how it works?
Each annotation can only be written in certain places. Those places are determined by the @Target
meta-annotation on the annotation's definition. For example, if an annotation is declared as
@Target(ElementType.ANNOTATION_TYPE)
public @interface MyAnnotation {
...
}
then @MyAnnotation
may only be written on annotation declarations. You cannot write @MyAnnotation
on a field or class declaration, or on a type use. An annotation that may be written on annotation declarations is called a meta-annotation.
You can learn more about annotations from the Java annotations tutorial .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.