Do You Use the Optional Class as It Should Be
summary
25+ practical recipes for Java Optional show exactly what to do and what to stop doing: initialize with Optional.empty instead of returning null, never blindly call get(), prefer orElseGet over orElse for computed defaults, use orElseThrow (since Java 10) for custom exceptions, and prefer ifPresent/ifPresentOrElse, map vs flatMap, OptionalInt/Long/Double for primitives, and Optional::stream to hook into Stream pipelines. Also covers anti‑patterns: no Optional fields, constructor/setter/argument usage, or Optional for collections.
AI-written summary · about
chapters (7)
- 0:00Introduction to Optional
- 3:11Surviving null pointer exceptions
- 7:44Handling empty Optional values
- 13:59Consuming Optional effectively
- 23:14Designing APIs with Optional
- 33:37Advanced Optional usage
- 43:07Summary and conclusion
related talks
55mDo you use the Optional class as it should be?
57mDo You Use the Optional Class as it Should Be
50mDo you use the Optional class as it should be?
48mOptional
01h 05mJava 8: The Good, the Bad and the Ugly
02h 41mDesign Patterns Revisited in Modern Java
49mJava 8: the good, the bad and the ugly
57mTen Common mistakes made in Functional Java
