Java Stream How to - Create Callable Lambda








Question

We would like to know how to create Callable Lambda.

Answer

//from   w w w. j  a va  2 s . co  m
import java.util.concurrent.Callable;

public class Main {

  public static void main(String args[]) {
    Callable<String> c = () -> "Hello you!";
    try {
      System.out.println(c.call());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
  
}

The code above generates the following result.