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"
You can refer to a static method defined in the class using method references.
References to static methods A static method reference refers to a static method in a specific class. Its syntax is className::staticMethodName , where className identifies the class and staticMethodName identifies the static method. An example is Integer::bitCount .
static void method is a static method which does not return any thing. Static method can be called by directly by class name. void method is a method which also return nothing. But for calling simple method you have to create a class object and called method by object.
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.
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