Guest User

Untitled

a guest
Aug 17th, 2019
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private interface Add {
  2. int calculate(int a, int b);
  3. }
  4.  
  5. private interface Subtract {
  6. int calculate(int a, int b);
  7. }
  8.  
  9. private class Calculator implements Add, Subtract {
  10. public int calculate(int a, int b) {
  11. return a + b;
  12. // return a - b;
  13. }
  14. }
  15.  
  16. interface Calculator{
  17. public int calculate(BiFunction<Integer, Integer, Integer> operation, int a, int b);
  18. }
  19.  
  20. class CalculatorImpl implements Calculator{
  21. public int calculate(BiFunction<Integer, Integer, Integer> operation, int a, int b) {
  22. return operation.apply(a, b);
  23. }
  24. }
  25.  
  26. Calculator calc = new CalculatorImpl();
  27. System.out.println(calc.calculate((a, b) -> a + b, 10, 20)); //output 30
RAW Paste Data