App下載
首頁(yè)javalambdaJava Stream - 如何return Lambda方法

Java Stream - 如何return Lambda方法

我們想知道如何return Lambda方法。
public class Main {

  public static void main(String[] args) {
    new Thread(uncheck(() -> {
      Thread.sleep(1000L);
      System.out.println("done");
    })).start();
  }

  private static Runnable uncheck(RunnableEx ex) {
    return () -> {
      try {
        ex.accept();
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    };
  }

}

@FunctionalInterface
interface RunnableEx {
  public abstract void accept() throws InterruptedException;
}