0

How can one or all of the following be done. Get all classes during runtime in Scala

  1. in a package
  2. that extend a particular trait
  3. with a custom annotation
forkit
  • 51
  • 1
  • 6
  • 1
    Reflection. And this probably means you have an error in your design. – Luis Miguel Mejía Suárez Aug 10 '20 at 19:42
  • 2
    @LuisMiguelMejíaSuárez Actually not with standard reflection. – Dmytro Mitin Aug 10 '20 at 19:58
  • standard reflection doesn't work with scala. it's not very straight fwd. I've tried many different combos. – forkit Aug 11 '20 at 14:27
  • @forkit Standard reflection does work with Scala. Moreover such working standard reflections are Java reflection (runtime), Scala reflection (compile-time and runtime). Just finding all classes in a package is not a standard reflection task and is not easy because of JVM nature. Did you try libraries (Reflections, ClassGraph...)? – Dmytro Mitin Aug 11 '20 at 16:00

1 Answers1

0

Use proper IDE.

For example, in Intellij IDEA to achieve

  • (1) you can type package and then see suggestions.
  • (2) you can use Ctrl+H.

I think there is a way to do exactly what you want.

Or you can use compiler's meta format to analyze it by yourself.

Artem Sokolov
  • 810
  • 4
  • 8