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. This example uses the final syntax available in JDK 25.

  • Constructor Details

    • PatternMatchingSwitchPreviewExamples

      public PatternMatchingSwitchPreviewExamples()
  • Method Details