7

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"

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This awkward moment when i feel ashamed for my question :D
But for this specific case you might prefer Executor as it’s the natural Runnable -> void interface. That’s especially convenient as there are already API methods accepting an Executor where it makes sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.