Create nested FunctionalInterface - Java Lambda Stream

Java examples for Lambda Stream:Functional Interface

Description

Create nested FunctionalInterface

Demo Code



public class LamdaMain3 {
  public static void main(String[] args) {
    MathOperations mathOperationsSum = (a, b) -> System.out.println("Sum:" + (a + b));
    MathOperations mathOperationsSubtract = (a, b) -> System.out.println("Subtract:" + (a - b));
    Results results = (a, b, mathOperations) -> {
      mathOperations.operation(a, b);//from   w  ww  . j a va  2s . c o m
    };
    results.doOperation(4, 5, mathOperationsSum);
    results.doOperation(4, 5, mathOperationsSubtract);
  }

  @FunctionalInterface
  interface MathOperations {
    void operation(int a, int b);
  }

  @FunctionalInterface
  interface Results {
    void doOperation(int a, int b, MathOperations mathOperations);
  }

}

Related Tutorials