How to create a single annotation take multiple values โ€‹โ€‹in Java

I have an annotation called

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

which allows you to add annotations like this

 @JIRA( key = "JIRA1" ) 

is there any way for this to happen

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

the reason is that we are currently annotating the test against Jiraโ€™s task or fixing bugs, but sometimes, the value will be processed by the sonar. The problem is one test covering more than 1 error.

+8
java annotations sonarqube jira
source share
1 answer

Modify the key() function to return String[] , not String , then you can pass different values โ€‹โ€‹with String[]

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

Use it as below

 @JIRA(key = {"JIRA1", "JIRA2"}) 
+14
source share

All Articles