Reputation: 231
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 ?
Upvotes: 2
Views: 29
Reputation: 201439
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).
Upvotes: 1