title: Mutating instance or local object variables in Lambda java 8
body: <p>I know that for concurrency reasons I cannot update the value of a local variable in a lambda in Java 8. So this is illegal:</p>
  
  <pre><code>double d = 0;
  orders.forEach( (o) -&gt; {
       d+= o.getTotal(); 
  });
  </code></pre>
  
  <p>But, what about updating an instance variable or changing the state of a local object?, For example a Swing application I have a button and a label declared as instance variables, when I click the button I want to hide the label </p>
  
  <pre><code> jButton1.addActionListener((  e) -&gt; {
        jLabel.setVisible(false);
   });
  </code></pre>
  
  <p>I get no compiler errors and works fine, but... is it right to change state of an object in a lambda?, Will I have concurrency problems or something bad in the future?</p>
  
  <p>Here another example. Imagine that the following code is in the method doGet of a servlet
  Will I have some problem here?, If the answer is yes: Why?</p>
  
  <pre><code>String key = request.getParameter("key");
  
  Map&lt;String, String&gt; resultMap = new HashMap&lt;&gt;();  
  
  Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
  //Load map
  
  map.forEach((k, v) -&gt; {
      if (k.equals(key)) {
          resultMap.put(k, v);
      }
  });
   response.getWriter().print(resultMap); 
  </code></pre>
  
  <p>What I want to know is: When is it right to mutate the state of an object instance in a lambda?</p>