Method References for interface - Java Lambda Stream

Java examples for Lambda Stream:Method Reference

Description

Method References for interface

Demo Code


public class MethodReferencesMain2 {
  public static void main(String[] args) {
    Operation operation=(a,b,obj)->{obj.doOperation(a, b);};
    operation.doSomething(2, 3, (a,b)->{System.out.println(a+b);});
    operation.doSomething(2, 3, (a,b)->{System.out.println(a-b);});
    operation.doSomething(2, 3, (a,b)->{System.out.println(a*b);});
    operation.doSomething(2, 3, (a,b)->{System.out.println(a/b);});
  }//ww  w. j  av  a 2  s.c  om

  interface Interface {
    public void doOperation(int a, int b);
  }

  interface Operation {
    public void doSomething(int a, int b, Interface intr);
  }
}

Related Tutorials