java – What is lambda () -> {} in Java

The Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that allows you to remove a lot of boilerplate code. They have no access modifier (private, public, or protected), no return type declarations, and no names.

Let’s take a look at this example.

(int a, int b) -> {return a > b}

In your case, you can do something like below:

schedulerFuture = taskScheduler.schedule(new Runnable() {
     @Override 
     public void run() {
        // task details
     }
}, this);

Leave a comment