I use the Sun CodeModel code generator for my project. During this I came to the point to generate an annotation class. This class would have an array member which takes an empty array as default values. See the following example:
public class Container {
public @interface MyAnnotation {
MyValue[] myValues() default {};
}
}
I used this code to generate the Annotation
JCodeModel codeModel = new JCodeModel();
JDefinedClass myValueClass = codeModel._class(JMod.PUBLIC, "MyValue", ClassType.CLASS);
JDefinedClass containerClass = codeModel._class(JMod.PUBLIC, "Container", ClassType.CLASS);
JDefinedClass annotationClass = containerClass._annotationTypeDeclaration("MyAnnotation");
annotationClass.method(JMod.NONE, myValueClass.array(), "myValues");
but I have no idea how to generate the default declaration. It only generates the following:
public class Container {
public @interface MyAnnotation {
MyValue[] myValues();
}
}