0

I want to create a generic method where i can pass below BinaryOperatior as a parameter in the method for Arithmetic operation based on binary operator parameter do the arithmetic operation and then return the result but I am getting error like Ambiguous, both 'multiply(BigDecimal)' and 'multiply(BigDecimal, MathContext)' match

I know this error come because overloaded method inside Bigdecimal for multiply, subtract, etc but how to solve this problem or how can i use this?

BinaryOperator ao1=  BigDecimal::subtract;
BinaryOperator ao2=  BigDecimal::multiply;

See below images attached for referance:

enter image description here

Pleas help how can do this? Thanks in advance!

  • 1
    Don’t use raw types. Use `BinaryOperator ao1 = BigDecimal::subtract, ao2 = BigDecimal::multiply;` and there’s no problem. – Holger Mar 24 '22 at 07:25

0 Answers0