title: Why this in anonymous inner class represent different object that in lambda
body: <p>as <a href="https://www.tutorialspoint.com/java8/java8_lambda_expressions.htm" rel="nofollow noreferrer">read</a></p>
  
  <blockquote>
    <p>Lambda expression eliminates the need of anonymous class and gives a
    very simple yet powerful functional programming capability to Java.</p>
  </blockquote>
  
  <p>what I understand that lambda is replacement of inner classes with single method to eliminates the bulkiness of the code</p>
  
  <pre><code>public class Main {
  
      interface Foo {
          int x = 20;
          void bar();
      }
  
      public static void main(String[] args) {
          Main app = new Main();
          app.start();
      }
  
      int x = 10;
  
      public void start()
      {
          Main test = new Main();
          test.test(new Foo()
          {
              @Override
              public void bar() {
                  System.out.println("Inner Class X= " + this.x);
              }
          });
  
          test.test(() -&gt; System.out.println("Lambda X= " + this.x));
      }
  
      public void test(Foo foo) {
          foo.bar();
      }
  
  }
  </code></pre>
  
  <p>the output I get is </p>
  
  <pre><code>Inner Class X = 20
  Lambda X = 10
  </code></pre>
  
  <p>what I expect is </p>
  
  <pre><code>Inner Class X = 20
  Lambda X = 20
  </code></pre>