mardi 1 novembre 2016

Annotation.toString() omits double quotes from String attributes

How can I print the value of an Annotation's field with double quotes when it's a String? For instance:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface MyAnnotation {
    String myField();
}

@MyAnnotation(myField = "bla")
public class Test {

    public static void main(String[] args) {
        for (Annotation annotation : Test.class.getAnnotations()) {
            System.out.println(annotation);
        }
    }

}

The code above produces:

@MyAnnotation(myField=bla)

How can I change it to produce @MyAnnotation(myField="bla")?





Aucun commentaire:

Enregistrer un commentaire