bethrobson / Head-First-Design-Patterns

Code for Head First Design Patterns book (2020)
3.15k stars 1.92k forks source link

Command Pattern, Diner with Lambda, Exception java.lang.NullPointerException #40

Open sashkov opened 1 year ago

sashkov commented 1 year ago

We get the exception because in file src/headfirst/designpatterns/command/dinerLambda/Customer.java on line 12 we make just declaration of Lambda-object as a local variable, and not save the Lambda-object in instance variable "o":

public void createOrder() {
    Order o = () -> { cook.makeBurger(); cook.makeFries(); };
}

Therefore we have null-object in file src/headfirst/designpatterns/command/dinerLambda/Waitress.java on line 8: order.orderUp();