Last active
December 15, 2015 02:29
-
-
Save Denommus/5187389 to your computer and use it in GitHub Desktop.
Trying to make a closure in Java
This file contains 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
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