IntStream.sum (original) (raw)
Remi Forax forax at univ-mlv.fr
Wed Jan 16 05:15:43 PST 2013
- Previous message: IntStream.sum
- Next message: IntStream.sum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 01/16/2013 02:14 PM, Joe Bowbeer wrote:
Normally I would side with the stricter argument in order to avoid potential harm, but in this case I don't see the problem.
the problem is that id doesn't solve the overflow problem, it just hide it more.
Code quality tools will flag the (int), right?
yes, raising the number of false positive warnings.
And long can hold the result of MAXINT additions?
stream are sized is store in a long if a size if definite or can be infinite so it solves nothing.
Rémi
On Jan 16, 2013 4:01 AM, "Remi Forax" <forax at univ-mlv.fr_ _<mailto: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