2
public static void main (String[] args) {
    test((a,b)->a+b, 2, 3);
}

private static void test (Op a, int num1, int num2){
    System.out.println(a.op(num1, num2));
}

private static interface Op <T extends Number>{
    public T op(T num1, T num2);
}

in the second line i have bad operand types for binary operator +. What is it i am supposed to do to make this work ?

user6008337
  • 221
  • 3
  • 15
  • Possible duplicate of [How to add two java.lang.Numbers?](http://stackoverflow.com/questions/2721390/how-to-add-two-java-lang-numbers) – shmosel Jul 20 '16 at 02:00

1 Answers1

1

By adding the type to Op in test like

private static void test(Op<Integer> a, int num1, int num2) {
    System.out.println(a.op(num1, num2));
}

Then your code will output 5 (as I think you expected).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249