Java – can annotation processors be used for code generation?
•
Java
Suppose I define an annotation named @ myannotation
One class X is declared as:
@MyAnnotation class X { .... }
Now when compiling, I want to check all classes annotated with @ myannotation and generate some code for more java source files that need to be compiled in the same process
Is this possible using a Java annotation processor or some other tool?
Solution
You can look at this Java apt (annotation processing tool)
You can find an article on how to use it to generate code on the getting started page (1, 2, 3)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码