Test Case für geschachtelte Pattern erstellt

This commit is contained in:
luca9913 2023-03-22 18:42:13 +01:00
parent b1b7c23166
commit 0311f5ed77

View File

@ -0,0 +1,18 @@
import java.lang.String;
record Point(int x, int y) {}
enum Color { RED, GREEN, BLUE }
interface Shape {}
record ColoredPoint(Point pt, Color color) {}
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) implements Shape {}
class PatternMatching {
void printColorOfUpperLeftPoint(Shape shape)
{
switch (shape) {
case Rectangle(ColoredPoint(Point pt, Color color), ColoredPoint lowerRight) -> System.out.println("x: " + pt.x() + " / color: " + color + " / lowerRight: " + lowerRight);
default -> System.out.println("not a rectangle");
}
}
}