Is there any way other than using reflection to access the members of a anonymous inner class?
You can use local classes instead anonymous class. Look:
public class Test {
public static void main(String... args) {
class MyInner {
private int value = 10;
}
MyInner inner = new MyInner();
System.out.println(inner.value);
}
}
You can have reference of MyInner
type only in the method body though. So outside of the method you will not be able to use its fields/methods that are not declared in its super class (java.lang.Object
in this case) or interface.