小编Raj*_*h P的帖子

如何在注释处理器中获取注释方法的返回类型?

我正在学习编写自定义注释。我有一个简单的注释,需要验证方法的返回类型是否与注释中指定的返回类型匹配。下面是代码。

注释代码:

@Target(ElementType.METHOD)
public @interface ReturnCheck {
    String value() default "void";
}
Run Code Online (Sandbox Code Playgroud)

注释处理器:

@SupportedAnnotationTypes("com.rajesh.customannotations.ReturnCheck")
public class ReturnCheckProcessor extends AbstractProcessor {

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

        for ( Element element : roundEnv.getElementsAnnotatedWith(ReturnCheck.class) ) {

            //Get return type of the method


        }

        return false;
    }

}
Run Code Online (Sandbox Code Playgroud)

我想获取注释方法的返回类型,以便我可以将其与注释中指定的值进行比较。

如何获取方法的返回类型?

java annotations

1
推荐指数
1
解决办法
1096
查看次数

标签 统计

annotations ×1

java ×1