Lambda that does absolutely nothing

I needed to have a lambda expression of the functional interface Runnable that did nothing. I used to have a method

private void doNothing(){
    //Do nothing
}

and then use this::doNothing. But I've found an even shorter way to do this.


For Runnable interface you should have something like that:

Runnable runnable = () -> {};

Where:

  • () because run method doesn't receive args
  • {} body of run method which in this case is empty

After that, you can call the method

runnable.run();

The lambda expression I use now is:

() -> {}

Guava - Runnables.doNothing();