Since Java 8, the class Integerhas a static method sumthat adds two integers:
Integer
sum
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.
Integer::sum
(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.
(a, b) -> a * b
Math::multiplyExact
static int multiplyExact(int x, int y)Returns the product of the arguments, throwing an exception if the result overflows int.
static int multiplyExact(int x, int y)
Returns the product of the arguments, throwing an exception if the result overflows int.
You can do it yourself:
public static int mult(int a, int b) { return a * b; }
, , jdk-includes, , Math#multiplyExact (Math::multiplyExact), , .
Math#multiplyExact
Source: https://habr.com/ru/post/1658132/More articles:What good is doing here with the new Integer? - javaare these branch instructions dependent? - assemblyPublishoptions recursively creates cshtml files - asp.net-coreTypeless lambda expression - javaHow to program a stencil with Dask - pythonHow do you expand all objects in the console chrome view? - google-chromeJava Thread & Unix Process - javaWhy should I re-declare a virtual function from an inherited class? - c ++onRequestPermissionsResult does not return back to android activity - androidIndexing a numeric range in Solr - solrAll Articles