0

How can we find all classes which have methods annotated with Specific annotation using java reflection? For eg: I have various methods say A(), B(), C() annotated with @Annotation present across multiple classes say Class1, Class2, Class3.

How can I find this list containing Class1, Class2, Class3.

Thanks!

Lovey
  • 880
  • 3
  • 15
  • 31
  • You can examine methods using reflection, but there is no reliable way to scan all classes. You could write a hack that gets the CodeSource of a known class, assumes its URL is a .jar, and scans the .jar for .class files… but eventually your code will run in an environment where those assumptions are not valid. Class discovery is usually done with something like java.util.ServiceLoader, which relies on SPI descriptor files (which are simple text files). – VGR Jul 09 '16 at 02:20
  • I was not able to solve it by link provided above. However using following library it got resolved. https://github.com/ronmamo/reflections#reflectionutils – Lovey Jul 12 '16 at 03:44

0 Answers0