Created
August 24, 2011 04:19
-
-
Save michiakig/1167302 to your computer and use it in GitHub Desktop.
Java closures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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