From 0311f5ed77839f9143d9ccb65554827f1d504598 Mon Sep 17 00:00:00 2001 From: luca9913 Date: Wed, 22 Mar 2023 18:42:13 +0100 Subject: [PATCH] =?UTF-8?q?Test=20Case=20f=C3=BCr=20geschachtelte=20Patter?= =?UTF-8?q?n=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/parser/NestedPattern.jav | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/parser/NestedPattern.jav diff --git a/src/test/java/parser/NestedPattern.jav b/src/test/java/parser/NestedPattern.jav new file mode 100644 index 00000000..e1961eb0 --- /dev/null +++ b/src/test/java/parser/NestedPattern.jav @@ -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"); + } + } +} \ No newline at end of file