使用注释处理器获取方法的返回值
我是注释处理器的新手,我想知道是否有可能在注释处理过程中获得带注释的方法的返回值。例如,我有注释
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Parameters {}
,我有一个标记了此注释的类:
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ 0, 0, 0 }, { 1, 1, 2 }
});
}
是否有可能获得new Object [] [] {{0,0,0,0},{1,1,1,2}}
使用注释处理工具(APT)?
I am new to annotation processor, I wonder if it is possible to get the the return value of a method marked with annotations during annotation processing. For example, I have annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Parameters {}
and I have a class marked with this annotation:
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ 0, 0, 0 }, { 1, 1, 2 }
});
}
is it possible I get new Object[][] { { 0, 0, 0 }, { 1, 1, 2 } }
using annotation processing tool(apt)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以 Indoke 用反射通过过滤在您的班级中可用的方法列表中,并用您的自定义注释注释。您的代码看起来像这样:
其中
对象
是包含您方法的类的实例。Yes, you can invoke your method with reflection by filtering on the list of methods available in your class and annotated with your custom annotation. Your code will look something like this:
Where
object
is an instance of your class containing the your method.