javasun-codemodeljcodemodel

How can I generate/declare annotation field inside of Annotation?


I want to get something like this:

public @interface Unfinished {
  String value();
   String value() default "someVal";
}

The problem is I cannot use JFieldVar because it looks like this:

String value; //no parentheses 
String value = "someVal"; //no parentheses, no "default", "=" sign

Solution

  • One possible way is to use jDefinedClass.direct:

    annotationClass.direct("String value();")
    annotationClass.direct("String value() default \"someVal\";")
    

    But I don't like this approach. I'd to use something similar to JFielVar.