有没有办法引用返回void的静态方法?
我试过这个
public Function<Runnable, Void> runner = Platform::runLater;
但它会说“错误的返回类型,无法将void转换为java.lang.Void”
答案 0 :(得分:13)
如果您的方法没有返回值,请不要使用Function
界面。
改为使用Consumer<Runnable>
。
public Consumer<Runnable> runner = Platform::runLater;
represents an operation that accepts a single input argument and returns no result.