Annotation Processor - How to get the Class it is processing

本文介绍了如何使用Java Annotation Processor处理类注解,并通过实现特定接口来访问这些类。此外,还探讨了如何利用Element API进行反射式的源代码检查。

You are unable to access the Class the Annotation Processor is processing because the Class has not been compiled yet. Instead Java offers the analogous Elements api for reflection-style inspection of the input source.

The Element (which you found by using roundEnv.getRootElements()) has much more information about the class being compiled than just its name. A ton of useful information can be found by using the ElementVisitors:


http://stackoverflow.com/questions/18034626/annotation-processor-how-to-get-the-class-it-is-processing


自己出现的问题跟这个差不多,想访问Annotation Processor生成的java文件中的类。

最后解决办法:就是生成类中必须实现某个接口,而这个接口本身是已经存在的。然后调用这个接口就可以实现了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值