Consider this code:
object A {
  object AA extends A
  object AB extends A
  object AC extends A
}; class A
How is it possible to "see" the objects defined within object A at runtime?
I thought a method within object A with some simple reflection code would be enough, but it seems that the compiler flattens the object hierarchy at compile time and created the following class files:
- A.class– The class A
- A$class– The companion object of A
- A$AA$.class– The AA object
- A$AB$.class– The AB object
- A$AC$.class– The AC object
After compilation there is no sign about AA, AB or AC in the companion object A, which would have my magicMethod.
It seems that the ClassLoader class has some related methods to what I plan to do, but all seem to expect the exact String name of the class. Is there a way to ask the ClassLoader to find all class files starting with the class from which this method is called (A$) in the path of that class?
 
    