• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

does java annotations uses the java refection.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roberto,

I think i got your point.please correct me if i'm wrong.okey for a example, in JPA we can use @Entity to annotate classes as entities.when I apply what you said is to my example,JPA reference implementation uses java reflection to map the annotated class into database table.Am I right?.

Hope you reply.I need to clear my doubts becase I use annotations without knowing what you said early.

Thnaks & regards,

Nuwan Aramabge


 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. JPA, Struts, JSF (...) all of those guys use reflection to search for @annotations.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hebert Coelho wrote:Yes. JPA, Struts, JSF (...) all of those guys use reflection to search for @annotations.



yes, thanks you again for clearing the doubts.......
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic