Lambda expressions are an important new feature in Java SE 8. Lambda expressions allow you to replace functional interfaces with expressions. Lambda expressions are just like methods in that they provide a normal list of parameters and a body (a body, which can be an expression or a block of code) that uses those parameters.

Lambda expressions also enhance the collection library. Java SE 8 added two packages for batch operations on the collected data: the java.util.function package and the package. A stream is like an iterator, but with a lot of extra functionality. In summary,lambda expressions and streams are the biggest change since Generics and annotations were added to the Java language.

Syntax format:


Only one parameter () can be omitted

What Lambda expressions can do:

1. Complete the instantiation of interface or abstract class

For example, our thread creation:

This is how it was created before:

Public class My_Main


Public static void main(String[] args){

New Thread(new Runnable(){

Public void run(){ print (” the child thread output “);





Instead of using a Lambda expression, we could write:

Public class My_Main2


Public static void main(String[] args){

New Thread (() – > System. Out. Print (” the child Thread output “)). The start ();



It doesn’t look like Lambda expressions are pretty neat.

Such as:

Customize a game interface with a method in the interface

public interface AAction {

void work(String name);


Create classes to test

public class My_Main {

private static void t1(AAction aAction){

AAction. Work (” zhang “);


public static void main(String[] args) {