如何在 Java Annotation 中设置字符串数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20632940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:15:01 来源:igfitidea点击:
How to set String Array in Java Annotation
提问by Jakob Abfalter
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.
我想不通的是,如何设置多个作者,因为 author() 已经返回 String[] 这应该是可能的。
@CustomAnnot(author="author1","autor2", description="test")
doesn't work!
不起作用!
采纳答案by 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")