Do you use the Optional class as it should be?
summary
25+ concrete recipes for Java Optional with code-level rules: always initialize with Optional.empty, prefer ofNullable for possibly null values, and never call get without presence checks. Use orElseGet vs orElse to avoid unnecessary computation (cache vs DB example), prefer ifPresent/ifPresentOrElse to isPresent+get, use orElseThrow (Java 10) for exceptions, map vs flatMap for nested Optionals, Optional.stream to flatten results, avoid Optional in fields/parameters/collections, and use OptionalInt/Long/Double for primitives.
AI-written summary · about
chapters (17)
- 0:00Introduction and speaker intro
- 5:50What is Optional class and its purpose
- 8:18Avoiding NullPointerException with Optional
- 13:20Handling absent values with orElse
- 18:57Using orElseGet for computed values
- 21:47Throwing exceptions with Optional
- 22:52Consuming Optional values effectively
- 26:01Returning Optional in APIs
- 33:44Designing APIs with Optional
- 40:51Optional and collections
- 44:00Optional for nullable values
- 45:43Optional for numbers
- 46:47Equality checks with Optional
- 47:50Filtering and transforming Optional
- 50:16Mapping and flatMapping Optional
- 52:05Optional with Stream API
- 54:14Q&A and closing
related talks
48mDo 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
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
