I have a package
package one.two.three
and in that package I have
public trait first
public class Second
and
pubic class Third
I want to get all the classes and interface(in one.two.three) names as Strings. heard that the best way to do it is using reflection.
can someone tell me a way to do that thing please.
Well, that is a bit more complex task than one would thought.
For instance, you may have classes in the same package but in different locations (e.g., 2 JAR files loaded by an UrlClassLoader
may contain a package a.b.c
).
The best way is to use already existent tools and libraries, such as the Reflections API for instance (I'm not aware of a Scala wrapper or alternative yet). They offer a robust and well tested interface for such queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With