I know Class.getDeclaredClasses()
can obtains all the classes that it has declared but doesn't including anonymous classes.
I'd like to know is there a way to get all the enclosed classes via the enclosing class ? for example, I want to get the all enclosed classes defined in Root
for test purpose.
class Root{
void run(){
Runnable task = new Runnable(){
public void run(){}
};
task.getClass().getEnclosingClass();// return Root.class
// but I want to get all enclosed class via Root.class, for example:
// Root.class... == task.getClass()
}
}
the expected result is : [class of task]
.