--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