public class DotThis { void f() { System.out.println("DotThis.f()"); } public class Inner { public DotThis outer() { return DotThis.this; } } public Inner inner() { return new Inner(); } public static void main(String[] args) { DotThis dt = new DotThis(); DotThis.Inner dti = dt.inner(); dti.outer().f(); }}输出:DotThis.f()
public class DotNew { public class Inner{} public static void main(String[] args) { DotNew dn = new DotNew();// Inner dni = new Inner(); //不能从静态上下文中引用 DotNew.Inner dni =(new DotNew()).new Inner(); //也可以是这样写 DotNew.Inner dni2 = dn.new Inner();//外部返回类型.内部返回类型 dni = 外部实例引用.内部实例 }}