Class PatternMatchingSwitchFourthPreviewExamples

java.lang.Object
net.jrodolfo.java_evolution.java20.PatternMatchingSwitchFourthPreviewExamples

public class PatternMatchingSwitchFourthPreviewExamples extends Object
Demonstrates pattern matching for switch as refined in the Java 20 fourth preview.

Pattern matching for switch went through multiple preview rounds because it needed careful rules for null handling, guarded patterns, exhaustiveness, and interaction with sealed types. Java 20 continued that refinement before the feature became final in Java 21.

This class uses final JDK 25 syntax while documenting the Java 20 preview origin.

  • Constructor Details

    • PatternMatchingSwitchFourthPreviewExamples

      public PatternMatchingSwitchFourthPreviewExamples()
  • Method Details

    • classify

      public String classify(Object value)
      Uses switch patterns to classify values.
      Parameters:
      value - the value to classify
      Returns:
      a type-specific description