I'm working on a project where the following line is used to create a test Executor member variable instance:
private Executor executor = Runnable::run;
The code runs and compiles but I don't understand how Runnable::run
creates an instance of Executor
since both are different interfaces.
Is anyone able to explain? In particular:
Executor
implementation (since Executor
is a different interface)?Executor
is created? e.g. single threaded or pooledThanks.
Executor
is a @FunctionalInterface
:
public interface Executor {
void execute(Runnable command);
}
You can re-write it like this to actually understand it better probably:
Executor executor = (Runnable r) -> r.run(); // or Runnable::run
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