[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/CSapprenticeWT/OnJava8-Examples/master/innerclasses/DotThis.java [Back]  [Original]

// innerclasses/DotThis.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Accessing the outer-class object

public class DotThis {
  void f() { System.out.println("DotThis.f()"); }
  public class Inner {
    public DotThis outer() {
      return DotThis.this;
      // A plain "this" would be Inner's "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();
  }
}
/* Output:
DotThis.f()
*/

Web Proxy Viewer  |  New URL  |  Original Page