我正在使用注释处理器来处理方法参数的注释。Java注释处理器,带注释的注释类型
public void multiply(@IntArg int a){
...
}
用于参上的注释类型有注释,@Argument现在
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.PARAMETER})
@Argument
public @interface IntArg {
}
,我的注释处理器运行时,我要检查,如果一个参数注解(@IntArg
)具有@Argument
注解。我通过执行以下代码来完成此操作。
VariableElement param = ... //The parameter
for (AnnotationMirror mirror : param.getAnnotationMirrors()) {
Argument arg = mirror.getAnnotationType().getAnnotation(Argument.class);
if(arg != null) {//Args is always null
...
}
}
由于某种原因arg
始终为空。是否有理由不注释注释?
那么,你的参数没有'@ Argument'注释,所以'arg'总是'null' ... –
我没有得到参数的'@ Argument'注解,我得到注解在这种情况下,AnnotationType是IntArg。 – Joba