ChatGPT解决这个技术问题 Extra ChatGPT

如何在 Java Annotation 中设置字符串数组

我已经声明了这样的注释:

public @interface CustomAnnot 
{
    String[] author() default "me";
    String description() default "";
}

因此,一个有效的注释将是

@CustomAnnot(author="author1", description="test")

我想不通的是,如何设置多个作者,因为 author() 有 return String[] 这应该是可能的。

@CustomAnnot(author="author1","autor2", description="test")

不工作!

author={"author1","autor2"}

K
Kai Sternad

像这样做:

public @interface CustomAnnot {

    String[] author() default "me";
    String description() default "";

}

还有你的注释:

    @CustomAnnot(author={"author1","author2"}, description="test")

如何在运行时读取该值。我需要获得作者的所有价值