O'Reilly logo

Learning Java Functional Programming by Richard M Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Summary

In this chapter, we demonstrated several of the Java 8 functional features to create a Zork-like game. Using console input, a player can navigate through a world picking up and dropping items along the way. New worlds can be configured using a file containing the description of the world.

We showed how to use the command pattern to handle commands. The commands were implemented using a combination of lambda expressions and other methods. Adding command aliases involved adding a different keyword to a hash map of commands.

Streams were used in a number of places to simplify processing and make the code more readable. Also used in conjunction with lists and maps was the forEach method, which replaced the need for imperative loops.

At several ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required