Class PatternMatchingSwitchExamples
java.lang.Object
net.jrodolfo.java_evolution.java21.PatternMatchingSwitchExamples
Demonstrates pattern matching for switch, finalized in Java 21.
Before this feature, type-based dispatch usually meant an if chain
with repeated instanceof checks and casts. Pattern matching for
switch lets the switch expression branch directly on type patterns.
The feature is especially strong with sealed hierarchies because the compiler knows the permitted implementations and can help verify exhaustive handling.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceClosed command hierarchy used to demonstrate exhaustive switch handling.static final recordRestarts a service.static final recordStarts a service.static final recordStops a service. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionHandles a sealed command hierarchy with switch patterns.
-
Constructor Details
-
PatternMatchingSwitchExamples
public PatternMatchingSwitchExamples()
-
-
Method Details
-
describe
Handles a sealed command hierarchy with switch patterns.- Parameters:
command- the command to describe- Returns:
- a command description
-