Class SealedClassesExamples

java.lang.Object
net.jrodolfo.java_evolution.java17.SealedClassesExamples

public class SealedClassesExamples extends Object
Demonstrates sealed classes, finalized in Java 17.

Before sealed classes, Java could not directly express a closed hierarchy in the type system. A parent type was usually open to any accessible subtype, even when the domain had a known finite set of valid implementations.

A sealed type solves this by explicitly controlling which classes or interfaces may implement or extend it. This makes domain hierarchies easier to understand and safer to exhaustively handle.

  • Constructor Details

    • SealedClassesExamples

      public SealedClassesExamples()
  • Method Details

    • area

      public double area(SealedClassesExamples.Shape shape)
      Calculates the area for a known sealed shape hierarchy.
      Parameters:
      shape - the shape to measure
      Returns:
      the calculated area