ChatGPT解决这个技术问题 Extra ChatGPT

How to set String Array in Java Annotation

I have declared a annotation like this:

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

A valid Annotation therefore would be

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

What I can't figure out is, how to set more than one author, since author() has return String[] this should be possible.

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

doesn't work!

author={"author1","autor2"}

K
Kai Sternad

Do it like this:

public @interface CustomAnnot {

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

}

And your annotation:

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

How can I read that value at runtime. I need to get all the value of author