因为,我知道我们可以在自定义批注上应用@Target、@Retention、@Documented等批注。
但最近我看到@Constraint应用在自定义注释上。
我们可以在自定义批注上使用任何批注吗?它是如何工作的?
发布于 2020-06-09 22:09:07
每个注解只能写在特定的位置。这些位置由批注定义上的@Target元批注确定。例如,如果批注声明为
@Target(ElementType.ANNOTATION_TYPE)
public @interface MyAnnotation {
...
}那么@MyAnnotation只能写在注释声明上。不能在字段、类声明或类型使用上编写@MyAnnotation。可以写在注释声明上的注释称为元注释。
您可以从Java annotations tutorial了解有关注释的更多信息。
https://stackoverflow.com/questions/62268005
复制相似问题