如何创建单个注释在Java中接受多个值

时间:2012-09-28 09:50:33

标签: java annotations jira sonarqube

我有一个名为

的注释
@Retention( RetentionPolicy.SOURCE )
@Target( ElementType.METHOD )
public @interface JIRA
{
    /**
     * The 'Key' (Bug number / JIRA reference) attribute of the JIRA issue.
     */
    String key();
}

允许添加像这样的注释

@JIRA( key = "JIRA1" )

有没有办法让这种情况发生

@JIRA( key = "JIRA1", "JIRA2", .....  )

原因是,我们目前正在对测试进行注释 针对Jira任务或错误修复,但有时, 然后该值将由声纳解析。 问题是单个测试涵盖了超过1个bug。

1 个答案:

答案 0 :(得分:15)

key()功能更改为String[]而不是String,然后您可以使用String[]

传递各种值
public @interface JIRA {
/**
 * The 'Key' (Bug number / JIRA reference) attribute of the JIRA issue.
 */
String[] key();
}

使用如下

@JIRA(key = {"JIRA1", "JIRA2"})