IntStream.sum (original) (raw)
Joe Bowbeer joe.bowbeer at gmail.com
Wed Jan 16 05:14:39 PST 2013
- Previous message: IntStream.sum
- Next message: IntStream.sum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Normally I would side with the stricter argument in order to avoid potential harm, but in this case I don't see the problem.
Code quality tools will flag the (int), right?
And long can hold the result of MAXINT additions? On Jan 16, 2013 4:01 AM, "Remi Forax" <forax at univ-mlv.fr> wrote:
IntStream.sum have just been changed to return a long instead of an int and I don't think it's a good idea.
There is 3 ways to deal with overflows: 1) do nothing, the Java default semantics 2) throw an exception if overflown (using Integer.addExact by example) 3) use BigInteger all other ways are just half baked solution. This one is very bad because usually users will use it that way, int sum = (int)intStream.sum(); so it doesn't solve anything, just make the semantics awkward. sum() is just a shortcut for a reduce, so it should stick with the default Java semantics, if users want longs, they can use reduce with Long::add or Long::addExact. Rémi
- Previous message: IntStream.sum
- Next message: IntStream.sum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list