Java Stream How to - Create Converter functional interface








Question

We would like to know how to create Converter functional interface.

Answer

//www . j  ava2 s . co m

public class Main {
  public static void main(String... args) {
    Converter<String, Integer> integerConverter1 = (from) -> Integer.valueOf(from);
    Integer converted1 = integerConverter1.convert("123");
    System.out.println(converted1);   // result: 123

  }
}

@FunctionalInterface
interface Converter<F, T> {
    T convert(F from);
}

The code above generates the following result.