The following sections describe solutions to the preceding problems. Remember that there usually isn't a single correct way to solve a particular problem. Also, remember that the explanations shown here include only the most interesting and important details needed to solve the problems. Download the example solutions to see additional details and to experiment with the programs at https://github.com/PacktPublishing/Java-Coding-Problems.
Solutions
226. Initializing Optional
Initializing Optional should be done via Optional.empty() instead of null:
// Avoid
Optional<Book> book = null;
// Prefer
Optional<Book> book = Optional.empty();
Since Optional acts as a container (box), it is meaningless to initialize it...