Class PatternMatchingSwitchPreviewExamples
java.lang.Object
net.jrodolfo.java_evolution.java19.PatternMatchingSwitchPreviewExamples
Demonstrates the continued preview of pattern matching for switch in Java 19.
Type-based dispatch used to be written with chains of instanceof
checks and casts. Pattern matching for switch lets the switch itself
express the type patterns, making this style of branching more compact and
easier to audit.
Pattern matching for switch became final later, in Java 21. This example uses the final syntax available in JDK 25.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final recordstatic final record -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSwitches over a sealed hierarchy with type patterns.
-
Constructor Details
-
PatternMatchingSwitchPreviewExamples
public PatternMatchingSwitchPreviewExamples()
-
-
Method Details
-
describe
Switches over a sealed hierarchy with type patterns.- Parameters:
event- the event to describe- Returns:
- a type-specific event description
-