Java自定义注释接受另一个注释
如何编写接受另一个注释和值的自定义注释Java自定义注释接受另一个注释,java,Java,如何编写接受另一个注释和值的自定义注释 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface TestAnnotation{ Class<? extends TestAnnotationChild> annotation(); } 我想做一些类似的事情 @TestAnnotation(@TestAnnotationChild={values}) 我怎样才能做那样的事情呢?
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation{
Class<? extends TestAnnotationChild> annotation();
}
我想做一些类似的事情
@TestAnnotation(@TestAnnotationChild={values})
我怎样才能做那样的事情呢?你可以在你的
TestAnnotation
中有一个类型为TestAnnotationChild
的属性,就像它是一个字符串,或者其他任何东西一样
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
TestAnnotationChild child();
// Or for an array
TestAnnotationChild[] children();
}
用法
然而,这是你陈述的一部分
价值观呢
让我觉得你想做一件不寻常的事吗
您能澄清一下吗?您应该只使用
TestAnnotationChild value()代码>而不是类
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestAnnotation {
TestAnnotationChild child();
// Or for an array
TestAnnotationChild[] children();
}
@TestAnnotation(
@TestAnnotationChild(
value = "42",
anotherValue = 42
)
)