[英]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.