[Java] Lambda expression

About lambda expression

--An expression that can treat a method like a variable.

syntax ** (variable) = (method argument)-> {processing content} **

--The description of anonymous class can be described as a function type. -[Java] Anonymous class The anonymous class explained in is simpler and can be described in one line. --Please check while looking at the sample.

Sample.java


//Anonymous class, interface used in lambda expressions
interface I_Hello {
  public void print();
}

//Calling class
public class Sample {
	public static void main(String[] args) {
		//How to write an anonymous class
		I_Hello p = new I_Hello() {
			@Override
			public void print() {
				System.out.println("Hello World");
			}
		};
		p.print();

		//How to write a lambda expression
		I_Hello p2 = () -> { System.out.println("Hello World2"); };
		p2.print();

	}
}
Hello World
Hello World2

Recommended Posts

[Java] Lambda expression
Java lambda expression
java neutral lambda expression 1
Java lambda expression variations
java lambda expression memo
Java lambda expression [memo]
Studying Java 8 (lambda expression)
Review java8 ~ Lambda expression ~
Java lambda expression again
[Java] Functional interface / lambda expression
Java8 stream, lambda expression summary
Java basic learning content 9 (lambda expression)
What is a lambda expression (Java)
Now let's recap the Java lambda expression
java learning (conditional expression)
Quarkus saves Java Lambda! ??
Understand Java 8 lambda expressions
About Java lambda expressions
Introduction to lambda expression
Explain Java 8 lambda expressions
Java table expression injection
java regular expression summary
Java Lambda Command Pattern
How to use Java API with lambda expression
Java8 to start now ~ forEach and lambda expression ~
Java8 Lambda expression & Stream design pattern reconsideration --Command pattern -
Use Lambda Layers with Java
Java
Memoization recursion with lambda expression
Getting Started with Legacy Java Engineers (Stream + Lambda Expression)
Java
Java8 Lambda Expression & Stream Design Pattern Rethinking --Null Object Pattern -
Java8 Lambda expression & Stream design pattern reconsideration --Template Method pattern -
Assign a Java8 lambda expression to a variable and reuse it
Java8 Lambda Expression & Stream Design Pattern Rethinking --Chain of Responsibility Pattern -
Java lambda expressions learned with Comparator
[Introduction to Java] About lambda expressions
Is Java on AWS Lambda slow?
Hello World on AWS Lambda + Java
Try an If expression in Java
Getting started with Java lambda expressions
The origin of Java lambda expressions
How to use Java lambda expressions
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
Implement API Gateway Lambda Authorizer in Java Lambda
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)