Optional

Optional<T> represents a value that may be absent, to avoid returning null. You consume it with map, orElse, orElseThrow, or ifPresent, rather than with an unchecked get(). It is mainly used as a return type, rarely as a field or parameter.

Example

String nom = trouver(id).map(Client::nom).orElse("unknown");

Related concepts

The whole glossary