• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annotated class with reflection  RSS feed

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • 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.
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!