as read
Lambda expression eliminates the need of anonymous class and gives a very simple yet powerful functional programming capability to Java.
what I understand that lambda is replacement of inner classes with single method to eliminates the bulkiness of the 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(() -> System.out.println("Lambda X= " + this.x));
}
public void test(Foo foo) {
foo.bar();
}
}
the output I get is
Inner Class X = 20
Lambda X = 10
what I expect is
Inner Class X = 20
Lambda X = 20