Skip to content

Instantly share code, notes, and snippets.

@michiakig
Created August 24, 2011 04:19
Show Gist options
  • Save michiakig/1167302 to your computer and use it in GitHub Desktop.
Save michiakig/1167302 to your computer and use it in GitHub Desktop.
Java closures
public class Foo {
final int bar = 6;
final int[] flarp = new int[] {6};
public class Baz {
int bla() {
return bar;
}
int bloo() {
flarp[0]++;
return flarp[0];
}
}
public Foo.Baz makeBaz() {
return new Baz();
}
public static void main(String[] args) {
Foo f = new Foo();
System.out.println(f.makeBaz().bla()); // prints 6
System.out.println(f.makeBaz().bloo()); // prints 7
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment