Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get all the class names in a package with scala

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.

like image 228
bula Avatar asked Oct 20 '22 17:10

bula


1 Answers

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.

like image 181
rlegendi Avatar answered Oct 31 '22 11:10

rlegendi