title: java 8 local variable in stream.foreach
body: <p>I would like to use local variables in lambda functions but I get error:
  Please see the 1. and 2. points in the code.</p>
  
  <pre><code>class Foo {
      int d = 0; // 1. It compiles, but ugly, 2. doesnt compile
      public void findMax(List&lt;List&lt;Route&gt;&gt; routeLists) {
          int d = 0; // 2.Error : Local variable dd defined in an enclosing scope must be final or effectively final
          routeLists.forEach(e-&gt; {
              e.forEach(ee -&gt; {
                  d+=ee.getDistance();    
              });
  
          });
          ... doing some other operation with d
      }
  }
  </code></pre>
  
  <p>How can I use them whitout setting them as global variables ?</p>