如何在 Java Annotation 中设置字符串数组 [英] How to set String Array in Java Annotation

查看:32
本文介绍了如何在 Java Annotation 中设置字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have declared a annotation like this:

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

因此一个有效的注解是

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

我想不通的是,如何设置多个作者,因为 author() 已经返回 String[] 这应该是可能的.

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")

不起作用!

推荐答案

这样做:

public @interface CustomAnnot {

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

}

还有你的注释:

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

这篇关于如何在 Java Annotation 中设置字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆