title: Can Java Lambdas have state?
body: <p>In one of the arguments about differences between lambdas and anonymous classes, in this post:</p>
  
  <p><a href="https://stackoverflow.com/questions/22637900/java8-lambdas-vs-anonymous-classes">Java8 Lambdas vs Anonymous classes</a></p>
  
  <p>I read a claim that "Lambdas can have state" just like anonymous class instances. </p>
  
  <p>As far as I know, you cannot add <strong>user defined</strong> state that belongs exclusively to the lambda , since there is no way to define instance members on an implementation of a java lambda function.</p>
  
  <p>For example:</p>
  
  <pre><code>Runnable r=  () -&gt; { int x = 5;  }; // defines a local - no way to define instance
  Runnable r2 = new Runnable() {
      int x;  // defines state via instance member
      @Override
      public void run() {
          // TODO Auto-generated method stub
  
      }
  };
  </code></pre>
  
  <p>Just to clarify, I am not trying to introduce state to a lambda, as I think that goes against the intent. I am just trying to verify or disprove a claim of a technical nature that was made by a reputable source on the above stack overflow question.</p>