import java.lang.String; record Point(int x, int y) {} interface Shape {} record ColoredPoint(Point pt, String color) {} record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) implements Shape {} sealed class Color permits Blue, Red { } class PatternMatching { void printColorOfUpperLeftPoint(Shape shape) { switch (shape) { case Rectangle(ColoredPoint(Point pt, String color), ColoredPoint lowerRight) -> System.out.println("x: " + pt.x() + " / color: " + color + " / lowerRight: " + lowerRight); default -> System.out.println("not a rectangle"); } } }