Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 10 examples,I got error! #29

Open
antianchi opened this issue Jun 11, 2019 · 1 comment
Open

Chapter 10 examples,I got error! #29

antianchi opened this issue Jun 11, 2019 · 1 comment

Comments

@antianchi
Copy link

Can you run?I can not successfully run the OptionalMain.java.What went wrong,Here
public String getCarInsuranceName(Optional<Person> person) { return person.flatMap(Person::getCar) .flatMap(Car::getInsurance) .map(Insurance::getName) .orElse("Unknown"); }

I got NullPointException.The Exception:
image

@ThisSeanZhang
Copy link

maybe you can modify your Person.java like this

public class Person {

    private Car car;

    public Optional<Car> getCar() {
        return Optional.ofNullable(car);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants