Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom annotation processing

I need a help on java custom annotations, I know how to create annotations but I do not know how to process that.
I have gone through some information where I saw APT which is com.sun.mirror.* and another javax.annotation.processing.*, I got confused between two.

Can any one please guide me to process custom annotations and provide useful link.

like image 701
Madhavi Avatar asked Dec 02 '25 16:12

Madhavi


2 Answers

There is a difference between the old apt (annotation processing tool, in com.sun.mirror) and its successor, the Pluggable Annotation API (which is a part of javac since 1.6). The new API used for processing is in javax.annotation.processing.

The API used for analysing declaration elements of the source code is the Mirror API, its package is in javax.lang.model, that API has similarities with the Reflection API.

Many sources will probably talk about apt, but are still valid for the processor tool in javac. Just the packages and the way to run the processing tool have changed. Here is a tutorial.

like image 66
kapex Avatar answered Dec 05 '25 06:12

kapex


If you need to process annotations at/before compile time (i.e. for producing "side files") then use apt.

OTOH if you need to process annotations at runtime then just use java reflection to get annotation on particular class.

like image 25
Peter Knego Avatar answered Dec 05 '25 06:12

Peter Knego



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!