Wilddev007 wrote:If you can use JDK 6 instead, I strongly recommend instead using the standardized JSR 269 annotation processing built into javac.
I am just trying to understand and explore Annotations and apt.
I was wondering, is it possible to replace a method with a particular annotation with another piece of code ( another method) ?In general, no. However, it is possible to achieve some of that effect using the Decorator pattern and generating the superclass or subclass using apt; see the archives of this forum for past discussion.
What I have in mind is, lets say there is a method which does DB operations. I could write it initially assuming that it will be used on Oracle. But then I want to be able to replace this with code that can be used with Java DB if I want to change my architecture.As a general comment, it sounds to me like that functionality should be factored into an interface and then a factory could give the rest of your code some implementation of that interface, perhaps even using java.util.ServiceLoader in JDK 6. In other words, while it may be convenient to use annotation processing to manage generating variants of the same functionality, I recommend not baking in a hard source or class file dependency on this into your system.
If i have a special annotation on such methods, can i use apt to replace them all and generate new source files?