fork(1) download
  1. @FunctionalInterface
  2. interface ArithmeticFunction {
  3. public int calcualate(int a, int b);
  4. }
  5.  
  6. public class Main {
  7. public static void main(String args[]) {
  8. ArithmeticFunction addition = (a, b) -> a + b;
  9. ArithmeticFunction subtraction = (a, b) -> a - b;
  10.  
  11. int a = 20, b = 5;
  12.  
  13. System.out.println(perform(addition, a, b));
  14. // or
  15. System.out.println(perform((x, y) -> x + y, a, b));
  16.  
  17. System.out.println(perform(subtraction, a, b));
  18. // or
  19. System.out.println(perform((x, y) -> x - y, a, b));
  20. }
  21.  
  22. static int perform(ArithmeticFunction function, int a, int b) {
  23. return function.calcualate(a, b);
  24. }
  25. }
Success #stdin #stdout 0.08s 47980KB
stdin
Standard input is empty
stdout
25
25
15
15