~/talk

Do you use the Optional class as it should be?

Talkat Devoxx Ukraine 2020 · 2020-11-05..11-07· [java]
slides:none on file

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

  1. 0:00Introduction and speaker intro
  2. 5:50What is Optional class and its purpose
  3. 8:18Avoiding NullPointerException with Optional
  4. 13:20Handling absent values with orElse
  5. 18:57Using orElseGet for computed values
  6. 21:47Throwing exceptions with Optional
  7. 22:52Consuming Optional values effectively
  8. 26:01Returning Optional in APIs
  9. 33:44Designing APIs with Optional
  10. 40:51Optional and collections
  11. 44:00Optional for nullable values
  12. 45:43Optional for numbers
  13. 46:47Equality checks with Optional
  14. 47:50Filtering and transforming Optional
  15. 50:16Mapping and flatMapping Optional
  16. 52:05Optional with Stream API
  17. 54:14Q&A and closing
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.