Optional
summary
Java 8’s Optional is a small (<20 methods) return-type box that replaces null results and is often misused; guidelines include never use null for Optional, avoid Optional.get unless proven present, prefer map/flatMap/orElse/ifPresent, and don’t convert nullable fields or method parameters into Optionals. Java 9 adds Optional.stream and ifPresentOrElse/or; Optional stays non‑serializable to preserve future value‑type plans (Project Valhalla). Antipatterns: nested Optionals, Optionals in collections, clever stream hacks that hurt readability and cause memory/GC overhead.
AI-written summary · about
chapters (20)
- 0:00Introduction
- 0:40API without Optional
- 3:00Optional
- 5:56Find
- 7:27Get
- 8:15IsPresent
- 9:36Optional Get
- 10:37Optional Or Else
- 12:01Optional Map
- 13:57Chaining Methods
- 14:33Filter Method
- 16:42If Present
- 18:12Static Methods
- 19:26New Methods
- 24:10Examples
- 31:50Optional Methods
- 35:53Optional History
- 37:12Optional Serializable
- 39:09Optional and Field
- 42:29Summary Conclusion
related talks
55mDo you use the Optional class as it should be?
50mDo you use the Optional class as it should be?
57mDo You Use the Optional Class as it Should Be
48mDo You Use the Optional Class as It Should Be
01h 05mJava 8: The Good, the Bad and the Ugly
49mJava 8: the good, the bad and the ugly
47mBeyond lambdas, the aftermath
02h 41mDesign Patterns Revisited in Modern Java
