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 with null.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset