vach
vach

Reputation: 11377

Java 8 method reference to static void method

Is there a way to refer static method that returns void?

i've tried this

public Function<Runnable, Void> runner = Platform::runLater;

but it will say "bad return type, cannot convert void to java.lang.Void"

Upvotes: 7

Views: 3481

Answers (1)

Eran
Eran

Reputation: 393781

If your method has no return value, don't use the Function interface.

Use Consumer<Runnable> instead.

public Consumer<Runnable> runner = Platform::runLater;

It represents an operation that accepts a single input argument and returns no result.

Upvotes: 16

Related Questions