bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

Lambda.sum does not work with empty list. #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Put any empty list to sum and a ClassCastException is thrown.
2. Lambda.sum(Collections.emptyList(), Lambda.on(Person.class).getAge());
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
2.3.1. Windows XP.

Please provide any additional information below.

I think that class cast exception comes from returning 0.0 (Double) from this 
method that is tried to cast to Integer.

----  Lambdaj.sum

public static Number sum(Object iterable) {
  if (iterable instanceof Number) return (Number)iterable;
  Iterator<?> iterator = asIterator(iterable);
  return iterator.hasNext() ? aggregate(iterator, getSumAggregator(iterator.next())) : 0.0;
}

----------

Original issue reported on code.google.com by Nikkeri2...@gmail.com on 26 Aug 2010 at 11:55

GoogleCodeExporter commented 9 years ago
This works in version 2.0 but not in any newer version.

Original comment by Nikkeri2...@gmail.com on 27 Aug 2010 at 6:28

GoogleCodeExporter commented 9 years ago
Fixed in release 2.3.2

Original comment by mario.fu...@gmail.com on 28 Aug 2010 at 4:47