Java Stream How to - Create Callable with method reference








Question

We would like to know how to create Callable with method reference.

Answer

import java.util.UUID;
import java.util.concurrent.Callable;
/*  w  ww  . j av a  2 s .  com*/
public class Main {
  public static void main(String... args) {
    Callable<UUID> callable = UUID::randomUUID;
    try {
      System.out.println(callable.call());
    } catch (Exception e) {
      e.printStackTrace();
    }

  }
}

The code above generates the following result.