Reflection vs anonymous class
Test.java----
public class Test {
public void doSomething() {
Object anonym = new Object() {
public void foo() {
// ...
}
};
}
}
----
---
public static void main(String[] args) {
Class<?> testClass = Test.class;
List<Class<?>> anonymousClasses = testClass.getAnonymousClasses();
System.out.println(anonymousClasses.get(0).getMethods[0].getName();
// output: foo
}
---
En method med navnet getAnonymousClasses() findes ikke for Class.
Er det muligt at faa fat i "foo"?