Optional
Java Optional: a return type that puts possible absence in the signature, how to unwrap it, and where it does not belong.
Optional, a container holding either one value or nothing, added so a method can say "there might be nothing here" in its signature instead of in its documentation. Used as a return type it removes a whole class of null bugs; used as a field or a parameter it adds problems. It covers what the type tells a caller, a lookup rewritten with it, orElse, orElseGet and orElseThrow, the fallback that runs anyway, get() without a check, and where Optional does not belong. It leaves out the primitive versions such as OptionalInt.
Contents
8 cardsnot started