Java Stream How to - Return Lambda method








Question

We would like to know how to return Lambda method.

Answer

//from w ww . ja  v  a 2 s .c o  m
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;
}

The code above generates the following result.