title: Curious about lambda capture in Java
body: <p>I read <a href="https://www.baeldung.com/java-lambda-effectively-final-local-variables" rel="nofollow noreferrer">https://www.baeldung.com/java-lambda-effectively-final-local-variables</a> and many articles(stackoverflow) However, there are many unanswered questions.</p>
  <ol>
  <li>I don't know why you do capture (copy value) in lambda.
  The following code is part of the code from the link I attached.</li>
  </ol>
  <pre class="lang-java prettyprint-override"><code>Supplier&lt;Integer&gt; incrementer(int start) {
    return () -&gt; start++;
  }
  // start is a local variable, and we are trying to modify it inside of a lambda expression.
  
  </code></pre>
  <p>they says</p>
  <blockquote>
  <p>Well, notice that we are returning the lambda from our method. Thus, the lambda won't get run until after the start method parameter gets garbage collected. Java has to make a copy of start in order for this lambda to live outside of this method.</p>
  </blockquote>
  <p><code>start</code> variable's life cycle is <code>incrementer().</code> They both exist on the same stack and have a lifecycle together. But I don't understand why it says GC and it doesn't run.</p>
  <ol start="2">
  <li>why only local variable must final or effective final? they(baeldung) say It because <code>Concurrency Issues</code>.</li>
  </ol>
  <p>Since the stack is allocated for each thread, there can be no concurrency issues. Rather, why do local variables need to be final when static member variables can cause concurrency problems?</p>