Howdy, Nuwan!
I have read that java reflection is working behind the scene of annotations.
Q1) is it true?
Q2) how does reflection help to make annotations useful?
Q1: Well, depends on what you mean by "working behind the scene of annotations". An annotation is simply a form of metadata.
Q2: An annotation does not do anything alone. It can't contain code, which means that it needs other code to consume it. This is done with reflection. Here's an example:
Now, in order to verify if an annotation annotates one element of your class (the doStuff() method in the example above), you can use reflection:
Most of the metadata-based frameworks nowadays use annotations. Spring,
EJB, JPA, Hibernate Validator are examples of such frameworks.
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD