~/talk

Enums on steroids - let's look at sealed classes!

Talkat GeeCON 2023 · 2023-04-19..04-21· [java, compilers-and-language-design]
slides:none on file

Claim: sealed classes plus records and pattern matching replace enums to model mutually exclusive outcomes. Implementation uses Java 17+ features: a sealed Response interface with three permitted records Approval, Refusal, Suspension and a pattern‑matching switch. Built a loan evaluator returning three concrete types (three surprising benefits: no instanceof casts, no default branch, and simpler tests). Pattern matching is still a preview feature so Maven/Gradle flags are required to compile, but the example compiles and runs and removes the previous response class smell.

AI-written summary · about

  1. 0:00Introduction
  2. 1:51Problem with enums
  3. 3:15First solution attempt
  4. 5:41Code smell in response class
  5. 7:29Introducing class hierarchy
  6. 8:54Using records for immutable data
  7. 9:35Pattern matching in Java
  8. 10:38Preview feature disclaimer
  9. 11:22Improved loan application
  10. 12:06Sealed classes introduction
  11. 13:54Final solution with sealed classes
  12. 15:41Testing improvements
  13. 16:04GitHub repository and Q&A
~/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.