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.
You can think of lambda expressions as anonymous methods (or functions) as they don't have a name. A lambda expression can have zero (represented by empty parentheses), one or more parameters. The type of the parameters can be declared explicitly, or it can be inferred from the context.
Calling type(None) will return you the NoneType constructor, which you can use for doing nothing: type(None)() . Keep in mind that the NoneType constructor only takes 0 arguments. In Python 2, though, creating instances of NoneType is impossible, so lambda: None would make the most sense.
This is probably one of the simplest Java annotation processing libraries out there. It generates no-op implementations of your interfaces.
A no op (or no-op), for no operation , is a computer instruction that takes up a small amount of space but specifies no operation. The computer processor simply moves to the next sequential instruction.
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 emptyAfter that, you can call the method
runnable.run();
The lambda expression I use now is:
() -> {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With