diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalAndLambda.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalAndLambda.java new file mode 100644 index 0000000000..d8e0815797 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalAndLambda.java @@ -0,0 +1,10 @@ +package com.baeldung.concurrent.localvariables; + +public class LocalAndLambda { + public static void main(String... args) { + String text = ""; + // Un-commenting the next line will break compilation, because text is no longer effectively final + // text = "675"; + new Thread(() -> System.out.println(text)).start(); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalVariables.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalVariables.java new file mode 100644 index 0000000000..39cae8da81 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/localvariables/LocalVariables.java @@ -0,0 +1,20 @@ +package com.baeldung.concurrent.localvariables; + +import java.security.SecureRandom; + +public class LocalVariables implements Runnable { + private int field; + + public static void main(String... args) { + LocalVariables target = new LocalVariables(); + new Thread(target).start(); + new Thread(target).start(); + } + + @Override + public void run() { + field = new SecureRandom().nextInt(); + int local = new SecureRandom().nextInt(); + System.out.println(field + " - " + local); + } +}