title: Why can I not reference the variable from within a lambda in this case?
body: <p>I have got the following code, which is somewhat abstracted from a real implementation I had in a Java program:</p>
  
  <pre><code>BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  String line;
  while ((line = bufferedReader.readLine()) != null) {
      String lineReference = line;
      runLater(() -&gt; consumeString(lineReference));
  }
  </code></pre>
  
  <p>Here I need to use a reference copy for the lambda expression, when I try to use <code>line</code> I get:</p>
  
  <blockquote>
    <p>Local variables referenced from a lambda expression must be final or effectively final</p>
  </blockquote>
  
  <p>It seems rather awkward to me, as all I do to fix it is obtain a new reference to the object, this is something the compiler could also figure out by itself.</p>
  
  <p>So I would say <code>line</code> is <em>effectively final</em> here, as it only gets the assignment in the loop and nowhere else.</p>
  
  <p>Could anyone shed some more light on this and explain why exactly it is needed here and why the compile cannot fix it?</p>