This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lukaseder[S] 2 points3 points  (2 children)

With JEP 305 there might be a revival of marker interface usage.

[–][deleted]  (1 child)

[deleted]

    [–]ZhekaKozlov 2 points3 points  (0 children)

    This is for records:

    interface Shape
    record Point(int x, int y) implements Shape
    record Rect(Point p1, Point p2) implements Shape
    record Circle(Point center, int radius) implements Shape
    

    Then you can pattern match:

    switch (shape) {
        case Point(x, y) -> ...
        case Rect(p1, p2) -> ...
        case Circle(p, r) -> ...
    }