Do you use the Optional class as it should be?
summary
Claims that 65% misuse Optional, lists concrete anti‑patterns and replacements: avoid Optional as fields, constructor args, collection values; use Optional.empty and ofNullable for safe construction; prefer orElseGet for lazy defaults and orElseThrow (Java 10) for exceptions to prevent unnecessary DB/cache calls; use map/flatMap and Optional.stream to stay in the pipeline; prefer primitive Optionals (Int/Long/Double) to avoid boxing; notes isEmpty (Java 11) and ifPresentOrElse for clearer control flow and equals compares contained values.
AI-written summary · about
chapters (29)
- 0:00Intro
- 1:18Presentation
- 8:30Use or else
- 13:28Exception
- 17:14If present
- 26:23Antipatterns
- 26:40Optional
- 27:34Serializable
- 28:05Option construction arguments
- 29:05Optional of nullable
- 30:03Optional of setters
- 31:52Make it simple
- 32:22Dont overuse also preferable
- 32:56Dont use return to collections
- 33:35Dont use avoid
- 34:08Performance and footprint
- 35:37Optional off
- 36:59Optional with numbers
- 37:49Optional with functional programming
- 38:40Optional with testing
- 40:02Reject the value
- 40:44Filter option
- 41:19Is present
- 42:01Transformation
- 42:58Map
- 43:16Math
- 44:36Flatmap
- 46:56Chaining
- 48:06OptionalStream
related talks
48mDo You Use the Optional Class as It Should Be
55mDo you use the Optional class as it should be?
57mDo You Use the Optional Class as it Should Be
48mOptional
02h 41mDesign Patterns Revisited in Modern Java
01h 05mJava 8: The Good, the Bad and the Ugly
47mBeyond lambdas, the aftermath
49mJava 8: the good, the bad and the ugly
