Skip to content

Instantly share code, notes, and snippets.

@simonharrer
Last active December 11, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonharrer/4665424 to your computer and use it in GitHub Desktop.
Save simonharrer/4665424 to your computer and use it in GitHub Desktop.
Code Puzzler - Different Behaviour in Java and Groovy
package betsy;
public class CodePuzzler {
public static void main(String[] args) {
// init array
String[] array = new String[2];
array[0] = "One";
array[1] = "Two";
// iterate and print in thread
for(final String element : array){
new Thread() {
public void run() {
System.out.println(element);
}
}.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment