2012-09-28 46 views
8

我有一个名为如何创建一个注释接受多个值在Java中

@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个错误。

+0

尼斯使用注释通过各种值。 – Saintali

回答

14

更改key()函数返回String[]而非String那么你可以使用String[]

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

使用它像下面

@JIRA(key = {"JIRA1", "JIRA2"}) 
相关问题