Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
JaGo
//Java: http://www.tutorialspoint.com/compile_java8_online.php?PID=0Bw_CjBb95KQMcXlnei1ncXh4Smc
//Golang: https://play.golang.org/p/ZgsqYqcrid
import java.util.*;
public class LambdaCapture {
public static void main(String []args) {
List<String> strings = new LinkedList<String>();
strings.add("one");
strings.add("two");
strings.add("three");
List<Runnable> runners = new LinkedList<Runnable>();
strings
.forEach(s -> {
System.out.println(s);
runners.add(
() -> {
int i = runners.size();
System.out.println(s + " " + i);
}
);
});
runners
.forEach(
r -> r.run()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment