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