3

Java 注释处理(从 Java 6 开始)是一个非常好的概念,因为它允许通过Element接口(和其他接口)访问有关类和方法的大量信息。

但遗憾的是,我不得不凭经验发现,未注释的类永远不会传递给自定义注释处理器:

warning: No SupportedAnnotationTypes annotation found on
    my.TESTProcessor, returning an empty set.

我的发现是真的吗?或者我可以“欺骗”编译器来提供关于非注释类的自定义注释处理器信息吗?

4

1 回答 1

5

伟大的!

这给了我真正的所有课程,而不仅仅是带注释的课程:

@SupportedAnnotationTypes("*")

该注释的规范说:

[...] Finally, "*" by itself represents the set of all annotation types,
including the empty set. Note that a processor should not claim "*"
unless it is actually processing all files [...] 

经测试,有效

于 2010-11-07T13:00:28.787 回答