susan.harkins-LOCKED (26) [Avatar] Offline
#1
Please share post-publication errors in this folder. We'll compile and publish a comprehensive list for everyone's convenience. Thank you!

Susan Harkins
Errata Editor
undjask (13) [Avatar] Offline
#2
10.3.3 Optional<People> typo
The example in 10.3.3 is as follows

Optional<Person> optPerson = Optional.of(person);
Optional<String> name =
optPerson.map(Person::getCar)
.map(Car::getInsurance)
.map(Insurance::getName);

But the text refers to Optional<People>

"[...]Why? The variable optPeople is of type Optional<People>, so itÂ’s perfectly fine to call the map method.[...]"
405563 (1) [Avatar] Offline
#3
I'm wondering about chapter 10, on Optionals. You say that if an insurance company doesn't have a name, that indicates a bug or a problem in your data. But when I look at https://github.com/java8/Java8InAction/blob/master/src/main/java/lambdasinaction/chap10/OptionalMain.java, if Insurance::getName returns null, the getCarInsuranceName() method will return "Unknown". Shouldn't it throw an exception (probably a NPE) instead?
353164 (3) [Avatar] Offline
#4
I believe the intent of Optional is to allow us to move away from having to catch the JVM driven NPE as a result of accessing null references. Ultimately, what you are referring to here is something that is driven by a bug in your data. In keeping with a domain driven design - we would want to catch the NPE and then throw our own exception back to the caller, letting them know that something went wrong. However, there can be several reasons for an NPE - especially if it occurs deep within an algorithm. Using an Optional would allow us to not only make the reference null safe, but would allow us greater flexibility in checking for domain specific errors, and thus allowing us to respond appropriately to those errors by throwing our own domain driven exception.
mhalver (33) [Avatar] Offline
#5
On page 316, the wrong arrow type ("->") is used for the Scala example (it should use "=>").

The example should read

def numbers(n: Int): Stream[Int] = n #:: numbers(n+1)

def primes(numbers: Stream[Int]): Stream[Int] = {
    numbers.head #:: primes(numbers.tail filter (n => n % numbers.head != 0))
}


I am not finding it as I write this, but I believe that I have seen the Java 8 style arrow used in a few of the other Scala code examples as well.
466838 (1) [Avatar] Offline
#6
On page 174, Section 7.3, 1st edition:

Collections now implements the interface Spliterator, which provides a method spliterator...


I think it should be corrected to:

The Iterable interface, implemented by all collections, now provides a method spliterator...

467066 (1) [Avatar] Offline
#7
1st edition and I saw it on MEAP (2nd ed. early release - free chapter).

Section 2.2.1 Fourth attempt: filtering by abstract criteria

title: PASSING CODE/BEHAVIOR

the code that shows:

public class AppleRedAndHeavyPredicate implements ApplePredicate {
    public boolean test(Apple apple){
        return "red".equals(apple.getColor()) 
            && apple.getWeight() > 150; 
    } 
} 

List<Apple> redAndHeavyApples =  
       filter(inventory, new AppleRedAndHeavyPredicate());


Must be

public class AppleRedAndHeavyPredicate implements ApplePredicate {
    public boolean test(Apple apple){
        return "red".equals(apple.getColor()) 
            && apple.getWeight() > 150; 
    } 
} 

List<Apple> redAndHeavyApples =  
     filterApples(inventory, new AppleRedAndHeavyPredicate());



filter must be changed to filterApples.