• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Annotated class with reflection

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a use case wherein i have multiple classes and i am trying to annotate all of those classes. I am trying to build a map of all the annotated fields of all the classes at startup with the actual field names so that when a user gives me annotated field name i can map it to actual field names.
So my first start was to create my own annotation class and annotate all the fields of the classes with it providing a name. But how do i build a map and find out all the classes that are annotated with my annotation.
 
Saloon Keeper
Posts: 15524
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, your annotation needs a retention policy "runtime". Then, you can scan the classpath for all classes containing certain annotations. There are libraries out there that do it, just google for classpath scanning and annotations.
 
reply
    Bookmark Topic Watch Topic
  • New Topic