java有可能在注释中有条件地应用注释吗?
我试着做如下事情:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnotationOne {
boolean annotationTwoToggler() default false
{
if (annotationTwoToggler) {
// Apply annotation AnnotationTwo to calling type
}
}
}
我将如何使用这个示例:
@AnnotationOne(true) // Implies AnnotationTwo
public class MyClass { ... }
AnnotationTwo
及其实现在我使用的API中,不能更改。我想让AnnotationTwo
的所有实现在给定true
参数的情况下触发AnnotationOne
我该怎么做
共 (0) 个答案