0

For example, I can specify Math::cbrt to tell the lambda to take the cube root of the value.

Can I refer to multiplication and division functions using method references?

Obviously I can make my own lambda but it would be nice to have consistency.

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • You mean like `IntBinaryOperator op = Math::multiplyExact;`? – Tunaki May 17 '16 at 13:51
  • _Are there method references [...]?_ Method references can exist for anything, in the appropriate _context_. – Sotirios Delimanolis May 17 '16 at 13:52
  • @Tunaki - No - like `Double y = x * Math.Pi;` but using method references. – OldCurmudgeon May 17 '16 at 13:55
  • @OldCurmudgeon Not sure I understand. The method-reference would refer to `multiplyExact`. And you apply that on some values. But if what you mean is to refer to `*`, then I don't think there's a built-in for that. – Tunaki May 17 '16 at 13:57
  • 2
    There has to be a method for there to be a method reference. – Sotirios Delimanolis May 17 '16 at 13:58
  • It sounds a bit like you want something similar to the `operator` module in python. Don't know if Java provides one, but it would be interesting to see if it did. – FatalError May 17 '16 at 13:58
  • @Tunaki - `MultiplyExact` takes `(int,int)`. I want something like `Math::multiply` just like `Math::cbrt`. – OldCurmudgeon May 17 '16 at 13:59
  • 2
    Then I think you need to make your own. There is `Double::sum` for the plus operation but that's it. It's pretty straight-forward: `public static double multiply(double a, double b) { return a * b; }`. And then you can refer to that method. – Tunaki May 17 '16 at 14:00
  • There isn't one in the library, as the default operators don't have a method. You could always write your own `PiMultiplier implements DoubleBinaryOperator` – Zymus May 17 '16 at 15:25

1 Answers1

0

To quote Sotirios Delimanolis There has to be a method for there to be a method reference.

And - since there aren't methods to do x * y (except perhaps in BigInteger) the answer is there are no method references to the in-line math functions.

Community
  • 1
  • 1
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213