Class PatternMatchingSwitchPreviewExamples

java.lang.Object
net.jrodolfo.java_evolution.java19.PatternMatchingSwitchPreviewExamples

public class PatternMatchingSwitchPreviewExamples extends Object
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. The type-pattern form shown here was part of the Java 19 preview and remains faithful to it.

  • Constructor Details

    • PatternMatchingSwitchPreviewExamples

      public PatternMatchingSwitchPreviewExamples()
  • Method Details