繁体   English   中英

Java 8方法引用静态void方法

[英]Java 8 method reference to static void method

有没有办法引用返回void的静态方法?

我试过这个

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

但它会说“错误的返回类型,无法将void转换为java.lang.Void”

如果您的方法没有返回值,请不要使用Function接口。

请改用Consumer <Runnable>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM