Class PatternMatchingInstanceofExamples

java.lang.Object
net.jrodolfo.java_evolution.java16.PatternMatchingInstanceofExamples

public class PatternMatchingInstanceofExamples extends Object
Demonstrates pattern matching for instanceof, finalized in Java 16.

Before this feature, type checks usually required a separate cast after instanceof. That repeated the type and made simple type-dependent logic more verbose than necessary.

Pattern matching solves this by combining the type check and local variable binding in one expression.

  • Constructor Details

    • PatternMatchingInstanceofExamples

      public PatternMatchingInstanceofExamples()
  • Method Details

    • describe

      public String describe(Object value)
      Uses instanceof patterns to avoid a separate cast after a type check.
      Parameters:
      value - the value to inspect
      Returns:
      a type-specific description