Skip to content

Instantly share code, notes, and snippets.

@Denommus
Last active December 15, 2015 02:29
Show Gist options
  • Save Denommus/5187389 to your computer and use it in GitHub Desktop.
Save Denommus/5187389 to your computer and use it in GitHub Desktop.
Trying to make a closure in Java
import java.util.concurrent.atomic.AtomicReference;
public abstract class TestClosure {
public abstract int execute(int a);
}
public class MainClass {
public static void main(String[] args) {
final AtomicReference<Integer> x = new AtomicReference<Integer>(4);
TestClosure testClosure = new TestClosure() {
@Override
public int execute(int a) {
x.set(x.get()+1);
return a+x.get();
}
};
System.out.println(testClosure.execute(2));
System.out.println(x.get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment