I use scala 2.11.6 currently, possibly 2.11.7 in the future. Given compiled class files in the classpath, I want to do 2 things:
Find the
For the first question, you could use ClassUtil library. Note that it'll find Java classes, and the ones which correspond to object
s will have names ending in $class
. See also Scala Reflection - Loading or finding classes based on trait.
For the second, object
s are called "modules" in Scala reflection, so you don't need isSingletonObject(name)
; if it isn't, rm.staticModule(name).asModule
in your code will fail. There doesn't seem to be a way to check if it's a compiler-generated empty companion object (isSynthetic
returns false), but they will be ruled out by the subtyping check anyway (so will the static parts of Java classes, but you can also filter those out using isJava
).