简体   繁体   中英

Java 6 Annotations Repeating with or without parameter

I have the following annotation:

public @interface ExcludeVariable {
    String list();
}

I want to be able preprocessing this in two different ways

First:

@ExcludeVariable // without parameter
int a;

Second:

@ExcludeVariable(list="a,b") // with parameter
public void test(){
     int a;
     int b;
     int c;
}

In Java 8 there is an option to "repeat" annotations

http://docs.oracle.com/javase/tutorial/java/annotations/repeating.html

How to handle this in Java 6

Best regards

Use "default". Read more here

public @interface ExcludeVariable {
    String list() default "";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM