Java 9 adds three new methods to the Optional class: `stream()`, `or()`, and `ifPresentOrElse()`. `Optional::stream` enables clean conversion from a stream of optionals to a stream of present values using flatMap, and also allows lazy evaluation. `Optional::or` enables elegant chaining of fallback Optional sources via a Supplier, replacing verbose Java 8 patterns. `ifPresentOrElse` handles both present and empty branches in one call, though the author prefers a hypothetical chainable `ifPresent`/`ifEmpty` design. Primitive specializations (OptionalDouble, OptionalInt, OptionalLong) only receive `stream` and `ifPresentOrElse`, still lacking `map`.

5m read timeFrom nipafx.dev
Post cover image
Table of contents
▚ Optional▚ Optional [ Double | Int | Long ]▚ Reflection

Sort: