Finding Classes that implement a Trait via Reflection

Typically in java I use reflections.org whenever I need to scan for classes that implement an interface.
Something like:

new Reflections("some.package").getSubTypesOf(MyInterface.class)

I see that there is the reflections library scala-reflect, but am a bit lost and am pretty sure(really just assuming) that reflections.org won’t work for scala.
Is there something similar to reflections.org for scala or a recommended approach?

Thanks

Traits are compiled to interfaces. Probably sometimes a helper class is defined (pre Scala 2.12?), but the interface based inheritance hierarchy still holds. You should try if that “org.reflections” % “reflections” library works on Scala traits. I would guess it does.

1 Like

I’m not sure why I was thinking that scala compiled to some sort of voodoo, but reflections.org worked fine.

Thanks

Just make sure to understand Runtime Classes in Java vs. Runtime Types in Scala. Using a trait should be ok.

1 Like

Thanks. That’ll definitely save me some headaches down the road.