public static class Outer {
public int field;
public class Inner {}
}
// caller methods
public static void foo(Outer.Inner inner) {
// here I want to access the "field"
// tried the following, none worked
System.out.println(inner.Outer.field);
System.out.println(inner.Outer.this.field);
}
How do I access a non-static fields of a class from a reference of its non-static inner class in Java?
P.S
People kept saying it's bad design. Yes, I agree 100% this is bad "design". At least, it's bad for code that needs to be read by humans. But if this is for generated code, I think I'll get a pass. (have anyone tried reading code that comes out of Antlr, for eg?)