Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created May 28, 2013 16:34
Show Gist options
  • Save fcamel/5664081 to your computer and use it in GitHub Desktop.
Save fcamel/5664081 to your computer and use it in GitHub Desktop.
Java's special syntax to access outer class
$ cat Outer.java
class Outer {
class Inner {
void foo() {
System.out.println(Outer.this.x);
}
}
private int x = 3;
public static void main(String[] args) {
Outer outer = new Outer();
Inner inner = outer.new Inner();
inner.foo();
}
}
$ javac Outer.java
$ java Outer
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment