class test {
public static void main(String[] args) {
new test();
}
void method() {
class inside {
int a;
void methodinside() {}
}
}
}
我使用反射来声明类:
Class c = Class.forName("test");
Class[] cls = c.getDeclaredClasses();
for(Class cl : cls)
System.out.println(cl.getName());
但是,我的程序找不到里面的类
。
最佳答案
我认为没有找到本地类(在方法内定义的类)的方法。
你可以 try to enumerate all classes in the package然后使用 getEnclosingClass(与您正在寻找的相反)来过滤它们。
关于java - 使用反射在方法中检索类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664515/