Is there an analog of multiplication Integer :: sum?

Since Java 8, the class Integerhas a static method sumthat adds two integers:

public static int sum(int a, int b) {
    return a + b;
}

I can pass this method to higher functions through Integer::sum, which I find more readable than (a, b) -> a + b.

Is there a similar static method for multiplication, so I don't need to write (a, b) -> a * b? I could not find him in the classroom Integer.

+4
source share
2 answers

Math::multiplyExact

static int multiplyExact(int x, int y)

Returns the product of the arguments, throwing an exception if the result overflows int.

+5
source

You can do it yourself:

public static int mult(int a, int b) {
    return a * b;
}

, , jdk-includes, , Math#multiplyExact (Math::multiplyExact), , .

+5

Source: https://habr.com/ru/post/1658132/


All Articles