Using JavaPoet I'm trying to annotate a class with an annotation which has an array as a parameter value i.e.
@MyCustom(param = { Bar.class, Another.class })
class Foo {
}
I use AnnotationSpec.builder
and its addMember()
method:
List<TypeMirror> moduleTypes = new ArrayList<>(map.keySet());
AnnotationSpec annotationSpec = AnnotationSpec.builder(MyCustom.class)
.addMember("param", "{ $T[] } ", moduleTypes.toArray() )
.build();
builder.addAnnotation(annotationSpec);