Difference between Anonymous Inner Class and Lambda Expression | Code Factory

Anonymous Inner Class

package com.codeFactory;/**
* @author code.factory
*
*/
public class AnonymousClass {
public static void main(String... args) {
Name name = new Name() {

@Override
public void getName() {
System.out.println("Name : " + name);
}
};
name.getName();
}
}
interface Name {
String name = "Code Factory";
void getName();
}

Lambda Expressions

package com.codeFactory;/**
* @author code.factory
*
*/
public class LambdaExpressions {
public static void main(String... args) {
Name name = (x) -> System.out.println("Name : " + x);
name.getName("Code Factory");
}
}
interface Name {
void getName(String name);
}

Difference :

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store