September 2019
Intermediate to advanced
816 pages
18h 47m
English
The do not use category continues with the following statement—Optional was not intended to be used for fields and it doesn't implement Serializable.
The Optional class is definitively not intended to be used as a field of a JavaBean. So, do not do this:
// Avoidpublic class Book { [access_modifier][static][final] Optional<String> title; [access_modifier][static][final] Optional<String> subtitle = Optional.empty(); ...}
But do this:
// Preferpublic class Book { [access_modifier][static][final] String title; [access_modifier][static][final] String subtitle = ""; ...}