On Tue, Jun 11, 2019 at 9:52 AM Heinrich Bohne <heinrich.bohne@gmx.at>
wrote:
> The class ArithmeticUtils in the commonsnumberscore module contains
> several methods where, since Java 8, equivalent methods in
> java.lang.Math exist. These methods are the following:
>
> addAndCheck(int, int)
> addAndCheck(long, long)
> mulAndCheck(int, int)
> mulAndCheck(long, long)
> subAndCheck(int, int)
> subAndCheck(long, long)
>
> The corresponding methods from java.lang.Math are:
>
> addExact(int, int)
> addExact(long, long)
> multiplyExact(int, int)
> multiplyExact(long, long)
> subtractExact(int, int)
> subtractExact(long, long)
>
> The former methods are probably relics from preJava8 times, when the
> latter methods did not exist.
Often true with commons, and no shame in that.
> But now, they are redundant. I suggest
> they be removed from ArithmeticUtils in commonsnumberscore, and their
> invocations replaced by invocations of the java.lang.Math equivalents.
>
+1
> Both groups of methods specify the same type of exception to be thrown
> in case of an overflow (a java.lang.ArithmeticException), so the
> replacement should be straightforward.
>
Utils classes are of course frowned upon in general, so IMO the less in
there the better.
