IntStream.sum (original) (raw)
Remi Forax forax at univ-mlv.fr
Wed Jan 16 03:58:02 PST 2013
- Previous message: Word Chain Kata
- Next message: IntStream.sum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
- do nothing, the Java default semantics
- throw an exception if overflown (using Integer.addExact by example)
- 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: Word Chain Kata
- Next message: IntStream.sum
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list