我可以使用JCodeModel生成注释类。我不明白如何将它添加到注释中:
@Target(value={METHOD,TYPE,CONSTRUCTOR})如何将定义值数组设置为值方法的值?对于简单的注释,我可以使用JAnnotationUse类的param()方法,但是如何将数组设置为我找不到的值。
发布于 2013-02-12 16:36:08
做一些类似的事情:
JAnnotationUse annotation = (JClass/JMethod/JFieldVar).annotate(Class<? extends java.lang.annotation.Annotation> MyAnnotation.class);
// Check if the value of the parameter of the annotation is an Array.
if (paramAnnotationValue.getClass().isArray()) {
Object[] paramAnnotationValueArray = (Object[]) paramAnnotationValue;
JAnnotationArrayMember annotationArrayMember = annotation.paramArray("parameter");
for (Object paramValue : paramAnnotationValueArray) {
annotationArrayMember.param((String/Boolean/Class/JType) paramValue);
}
}
// No Array is normal.
else {
(...)
}像这样的东西产生了:
@MyAnnotation(parameter = {
"value_a",
"value_b"
})https://stackoverflow.com/questions/12903876
复制相似问题