small medium large xlarge

13 Mar 2013, 12:46
Wacek Kusnierczyk (4 posts)

On p. 3 you give an example of the functional way of solving problems:

final double totalOfDiscountedPrices = price) -> price * 0.9).sum();

Since you earlier made a comment on the procedural way, “Those of us working from home have to keep this code away from the eyes of kids aspiring to be programmers”, I think you might want to find a better example. The above is still not what you’d want to show to your kids ;) as there is a much simpler solution:

final double totalOfDiscountedPrices = 0.9 *;

An example where the components would need to be squared, say, would be more to the point:

final double totalOfSquared = price) -> price * price).sum();

although it does not make much sense in the context of prices.

13 Mar 2013, 20:25
Venkat Subramaniam (98 posts)

Hi Wacek, nice point, I like the suggestion. Will make the change before the next beta release! Thanks.

16 Mar 2013, 14:20
Arjo Ouwens (1 post)

Little correction on a example in the book: page 34,

final List<String> uppercaseNames = new ArrayList<String>();
friends.forEach(name -> uppercaseNames.add(name.toUpperCase()));

but this will give you a compiler warning: “incompatibel return type boolean in lambda expression”.

Simple correction:

final List<String> uppercaseNames = new ArrayList<String>();
friends.forEach(name -> uppercaseNames.add(0, name.toUpperCase()));
17 Mar 2013, 03:01
Venkat Subramaniam (98 posts)

Hi Arjo, thank you for the suggestion.

I tried the first example code on both build 79 and build 81 (on the mac) and I am not getting any warning.

Could you help me with the settings you’re using so I can try to recreate it on my side.



09 May 2013, 14:09
carlo (1 post)


Reading your book which is great. Looking forward to the updates.

I tried the sample code with JDK 8 lambda build 88 and found that the sum() method on streams does not compile. Quite a few examples use sum().

I’m using Netbeans set to JDK 8 for source and libs.

public class DiscountFunctional { public static void main(final String[] args) { final double totalOfDiscountedPrices = price) -> price * 0.9).sum();

System.out.println("Total of discounted prices: " + totalOfDiscountedPrices);   } }

Exception in thread “main” java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: at fpij.DiscountFunctional.main( Java Result: 1

Wonder if sum() has been removed from the Java 8 ? I didnt see it in the Javadoc. Maybe there is another way to do it ?

Thanks Carlo

16 May 2013, 12:03
Venkat Subramaniam (98 posts)

Hi Carlo, thank you for your comments. The API has evolved and I need to make another update. I plan to get the next beta out with updates in June. Thanks. — Venkat

21 May 2013, 06:19
Marc-Daniel Ortega (3 posts)

Hi, I could not resist coming to the forum for chapter 8. Reproducing the example I noticed that currying the isPriceLessThan method as in this interface could add more symmetry into the findHighPrice method as in this implementation

Please note that the findHighPrice method has been curried too in order to make the max value flexible.

Using a windows environment less handy for measurements of time of execution, I created my one HOF timed in order to be able to trace the time execution of a supplier like function

The invocation of timed grossly emulate a rudimentary delay behavior.

Thanks for the wonderful work, and be sure next time you hop to Europe I manage to get a physical copy in addition to the numeric edition so you can sign it :)


16 Jun 2013, 16:10
Venkat Subramaniam (98 posts)

Hi Mark,

Thank you very much for so many wonderful suggestions. I enjoyed updating the book with each one of them.

Will certainly have to catch up next time our locales align.



05 Oct 2013, 08:56
Sven Ehrke (1 post)

In the book ‘Groovy in Action’ the authors are using assertions instead of System.out.printlns which I think has the advantage that the code itself expresses what is going on and you do not have to write: “this code prints…” And for the examples using lists lambdas then even make testing easier and more readable.

Example: ` assertEquals( “Brian-Nate-Neal-Raju-Sara-Scott”, friends().stream().collect(joining(“-“)) ); `

15 Oct 2013, 00:25
Venkat Subramaniam (98 posts)

Hi Sven, thanks for the suggestion. Good point, but as a matter of style I prefer running a code and seeing the output when learning a new language or a new feature. The other approach certainly has merits, it’s purely a preference here on my part. Regards, Venkat

05 Nov 2013, 03:24
GREG HELTON (2 posts)

Venkat, I have b3, Sep 18 version. The book does not include the code or a link to the code for Prices class referenced from

Located the code for Prices class at but maybe not everyone will find it.


26 Nov 2013, 06:19
Venkat Subramaniam (98 posts)

Greg, thanks. The code is listed on page 3 (it’s the first one line code on that page) and I left out the link with intention. Regards, Venkat.

20 Dec 2013, 13:16
Dan Talpau (2 posts)

Hi, I just finished Ch. 2 Using Collections and I think the reduce/collect concepts/methods could be explained a little bit better.

Compared to Clojure’s reduce() API, the one in Java 8 seems a little bit more complicated.

For me it was not obvious what difference between reduce and collect is. The Oracle docs made it more clear for me that collect() mutates the accumulated value, which might be important in some scenarios.

Also, the 3rd overloaded reduce() method that takes an identity, accumulator and combiner is the least intuitive and not mentioned in the book; it’s pretty well explained here why an accumulator and a combiner are needed:

Basically I would have liked to “get” Java 8 reduce/collect API from the book and not having to check Oracle docs/stackoverflow. Although maybe they are obvious for others.

20 Dec 2013, 21:36
Venkat Subramaniam (98 posts)

Dan, thank you very much for your feedback and suggestion. Your timing is great, I will have a window of opportunity in the next few weeks to touch the book (it is in the middle of production phase) and will see what I can do to improve in this area. Thanks a bunch. Venkat

21 Dec 2013, 20:49
Dan Talpau (2 posts)

As I progressed through the book, I saw that in Ch. 3 the collect() method is very well explained (using collect and Collectors); to my previous comment is a bit redundant :)

23 Dec 2013, 02:56
Venkat Subramaniam (98 posts)

Dan, thanks! Your comment is quite helpful, I will place a forward reference to what’s ahead. Cheers. :) Venkat

You must be logged in to comment