Errata

Java 8 Lambdas

Errata for Java 8 Lambdas

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
PDF
Page -1
Code on Github

In class Artist the method isFrom()
is:
public boolean isFrom(String nationality) {
return nationality.equals(nationality);
}

but should be:
public boolean isFrom(String nationality) {
return nationality.equals(this.nationality);
}

Note from the Author or Editor:
It looks like this is a valid errata report. Thanks for submitting the issue.

Stig Jacobsen  Nov 02, 2014  Aug 07, 2015
Your First Lambda Expression
The second code snippet of "button.addActionListener ..."

The code snippet was:

button.addActionListener(new ActionListener() {
public voidactionPerformed(ActionEvent event) {
System.out.println("button clicked");
}
});

which should have been:

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("button clicked");
}
});

i.e. a space was missing between "void" and "actionPerformed".

Note from the Author or Editor:
Looks like a legit piece of errata. There should be a space between void and action

Anonymous  Nov 06, 2017 
Other Digital Version
2%
Location 149 (Kindle), 8th paragraph of chapter 1

O bought the book at Amazon Kindle Store and this version has not page numbers. The issue is minimal, it is a little typo for the word 'readbility', where it should be readability.

Note from the Author or Editor:
Thanks for spotting this issue - I will have the typo fixed.

Michel Graciano  Apr 08, 2014  Aug 07, 2015
PDF
Page 6
first code sample, between 1st and 2nd paragraph

the text says "Look how much gray we get if we color out the boilerplate:", but there is no gray in the code sample that follows

Note from the Author or Editor:
There's an inline note in the text to have this greyed out during printing, but it hasn't happened.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 12
Example 2-11

The example is:

Predicate<Integer> atLeast5 = x -> x > 5;

though it compiles, the variable name is "wrong": it should be "atLeast6" or "greaterThan5" or something similar

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 13
error message under Example 2-14

It says:
Operator '+' cannot be applied to java.lang.Object, java.lang.Object.

but it should be:
Operator '+' cannot be applied to java.lang.Object, java.lang.Object.

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 14
Exercise 2b

The solution provided for this exercise doesn't compile for me.

File is located in the code download at this path:
src/test/java/com/insightfullogic/java8/answers/chapter2/Question2Test.java

Line with error:
String formatted = Question2.formatter.get().format(new Date(0));

Error as follows:

Error:(14, 61) java: cannot find symbol
symbol: method format(java.util.Date)
location: class javax.swing.text.DateFormatter

I cannot figure out a possible correction.

Thanks

Note from the Author or Editor:
Thanks for letting me know about this issue, and my apologies for it arising in the first place. I foolishly accepted a pull request that changed this example without checking it properly. I've pushed a fix to the github repository.

Patrick Huffer  Sep 01, 2014  Aug 07, 2015
, Other Digital Version
Page 14
Exercise 2b

Due to timezone considerations the provided test case may fail even if a proper solution is provided (included the one in the answers package). Something along the lines of the following might be better.

public void exampleInB() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 1970);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
String formatted = Question2.formatter.get().format(cal.getTime());
assertEquals("01-Jan-1970", formatted);
}
}

Note from the Author or Editor:
Valid errata report - I've already fixed and pushed it to the github project with the exercises in.

Russ Moul  Jan 08, 2015  Aug 07, 2015
PDF
Page 14
Exercise 2

Under point b., it says "DateFormatter" twice, this should be DateFormat (since it refers to java.text.DateFormat)

Note from the Author or Editor:
Fixed, though again its a typo.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
Printed
Page 19
Example 3-3

In Example 3-3 on page 19 of the printed book, the description says "Counting Liverpool-based artists using internal iteration", but the example contains the code:

.filter(artist -> artist.isFrom("London"))

where as previous examples (3-1 and 3-2) correctly use isFrom("Liverpool").

Note from the Author or Editor:
This is correct, it should say isFrom("Liverpool")

Anonymous  Jul 19, 2017 
PDF
Page 21
Example 3-6 and Example 3-7

Example 3-6 says: "artist.isFrom("London");"
Then the text and Example 3-7 use The Beatles as an example of what would be printed.

This is wrong, in the sense that The Beatles are from Liverpool. So either Example 3-6 should be changed to use Liverpool. Or the following text & Example 3-7 should be changed to use a London-based band instead, like e.g. The Rolling Stones.

Note from the Author or Editor:
Fair point, fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 22
in the middle

It starts
by taking a Stream from a List

should be

It starts
by taking a Stream from an Array

Note from the Author or Editor:
Thanks for spotting this - it is a mistaken description.

Randolf Rothfuss  Apr 13, 2014  Aug 07, 2015
PDF
Page 27
1st paragraph

While describing Example 3-13, the text says:
In this case we’ll use length, which is a getter function in disguise.

Since the concerned code is:
Comparator.comparing(track -> track.getLength())

I don't understand:
- why the text doesn't say "getLength" instead of "length"
- why it says it's a getter function "in disguise", since it really is just a getter function

Note from the Author or Editor:
Valid error, but really a typo in the text. Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 31
paragraph right after the code sample

The text says:
The calls to musicians, filter, and map all return Stream objects, [...]

I think "musicians" should be replaced with "getMusicians"

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
Printed, PDF, ePub
Page 38
Exercise5, example code

forEach(musicain -> count.incAndGet();) should be forEach(musicain -> count.incrementAndGet());

Note from the Author or Editor:
Thanks for reporting this error. I've fixed it in my repository and any future update will include a fix for this issue.

Li Hao Su  May 17, 2014  Aug 07, 2015
PDF
Page 45
2nd paragraph

The text says:
"A BinaryOperator is special type of BiFunction"

I think there should be an extra "a" after "is":
"A BinaryOperator is a special type of BiFunction"

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 46
bottom, one but last bullet

The text says:
"If there is a single possible target type, the lambda expression infers the type from the corresponding argument on the functional interface."

while I think it should read:
"[...] from the corresponding parameter of the functional interface method."

Note from the Author or Editor:
Certainly better wording.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 68
one but last paragraph

The text says:
"In this case, what we’re really trying to do is perform a map operation on the list from the Artist to the album name."

while it should say (Artist should be replaced with Album):
"[...] from the Album to the album name."

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 77
The last paragraph

The original is :

Historically,
the approach was to use the values method to get a Set of entries and then iterate over
them.

"the values method" should be "the entrySet method".

Note from the Author or Editor:
This is a valid errata, I've fixed it in the repository.

Justin Lin  Oct 16, 2014  Aug 07, 2015
PDF
Page 86
2nd paragraph

"closey" should be "closely"

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 86
Example 6-4

The method "simulateDiceRoles" (and its invocation) should be changed to "simulateDiceRolls" instead.

Note from the Author or Editor:
Fixed.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 88
one but last paragraph

The text says:
"If you do try to hold locks on any data structure that the streams library is using, such as the source collection of an operation, you’re likely to run into trouble."

What does "you’re likely to run into trouble" mean here? What kind of trouble, and in which cases (since you write "likely", which implies it's not a guarantee for trouble)? What's a concrete example?

Thanks in advance

Note from the Author or Editor:
I've added more detail in the text to address this issue.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 91
paragraph that starts with "Ideally, ..."

The text says: "Unfortunately, reality can get the way of the ideal at
times!"

but there's an "in" missing:
"[...] can get in the way [...]"

Note from the Author or Editor:
Valid errata, fixed in git repo.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 92
Example 6-7

Change the method name from "imperativeInitilize" (missing "a") to "imperativeInitialize"

Note from the Author or Editor:
Valid errata, fixed in git repo.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 102
last paragraph

The text says:
"Let’s take look Example 7-8"

This should be:
"Let's take a look at Example 7-8"

Note from the Author or Editor:
Valid issue, fixed in git repo.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 130
The paragraph before Example 8-37.

The original is :

If we want to speed up the time it takes to perform this operation at the expense of using
more CPU resources, we can use the parallelStream method without changing any of
the other code ....

According to Example 8-37, "the parallelStream method" should be "the parallel method".

Note from the Author or Editor:
There are both parallelStream() and parallel() methods which can be used for slightly different purposes. This is a genuine errata item and I've edited the text to refer to both.

Justin Lin  Oct 17, 2014  Aug 07, 2015
Printed, PDF, ePub, Mobi,
Page 148
(throughout page)

I suspect I may be misunderstanding something here, but I'm wondering if it would be more accurate to replace the following statement:

"What this means in the case of Example 9-9 is that we can't start either of the calls to the lookup services until we've logged into both of them"

with

"What this means in the case of Example 9-9 is that we can't start the second call to the lookup services until we've logged into both of them"

That is, it appears to be sufficient to only log into the track service in order to call lookupTracks(). It's only the call to lookupArtists() that's impacted negatively, by virtue of the fact that it occurs second.

If this is correct, it would also imply that the left-hand-side of Figure 9-3 is slightly inaccurate.



Note from the Author or Editor:
Hi,

Thanks for submitting this issue. You are correct. I've corrected the error in my text and any future editions will contain this fix. Unfortunately I can't correct this issue in people's copies without doing a completely edition release.

Anonymous  Jul 30, 2014  Aug 07, 2015
PDF
Page 148
paragraph that starts with "As you'll have noticed"

The text says: "This can be become a performance limitation"

It should be something like the following instead:
"This can become ..."
"This can be ..."
"This can be, or become, ..."
...

Note from the Author or Editor:
Fixed in git repo.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015
PDF
Page 156
Example 9-18

Inconsistent syntax coloring: in the method "isLargerGroup", the first invocation of "getNumberOfMembers" is purple, while the second invocation isn't.

Note from the Author or Editor:
This is a valid errata issue. I have no way of correcting this on my side, the syntax highlighting is done automatically by the atlas publication system.

Anthony Vanelverdinghe  Apr 03, 2015  Aug 07, 2015