How to set String Array in Java Annotation

JavaAnnotations

Java Problem Overview


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!

Java Solutions


Solution 1 - Java

Do it like this:

public @interface CustomAnnot {

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

}

And your annotation:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJakob AbfalterView Question on Stackoverflow
Solution 1 - JavaKai SternadView Answer on Stackoverflow