~/talk

Designing with Sealed Classes

slides:none on file

Sealed classes in modern Java close inheritance for plugin-style APIs so core abstractions can be public but not extensible, replacing brittle hacks like package-private constructors, runtime instanceof checks, or custom annotation processors. Example: a sealed TrafficLight with three permitted leaves (Red, Yellow, Green) compiles to bytecode that records permitted subclasses and the compiler rejects unauthorized subclasses at compile time; reflection exposes getPermittedSubclasses, and using sealed + final yields exhaustiveness for pattern matching. Modules widen where permitted subclasses may live.

AI-written summary · about

  1. 0:00Introduction to sealed classes
  2. 7:27Why restrict inheritance
  3. 16:45Hacky solutions for inheritance
  4. 26:38Sealed classes explained
  5. 38:09Practical sealed class example
  6. 45:54Non-sealed classes and use cases
  7. 57:05Reflection and pattern matching
  8. 1:00:16Summary and best practices
~/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.