从内部类对象获取外部类对象
inner
public class OuterClass { public class InnerClass { private String name = "Peakit"; } public static void main(String[] args) { OuterClass outer = new OuterClass(); InnerClass inner = outer.new InnerClass(); // How to get the same outer object which created the inner object back? OuterClass anotherOuter = ?? ; if(anotherOuter == outer) { System.out.println("Was able to reach out to the outer object via inner !!"); } else { System.out.println("No luck :-( "); } }}
编辑:
public OuterClass outer() { return OuterClass.this;}
红颜莎娜
汪汪一只猫
慕后森
相关分类