📜  Java 模式匹配 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:15.134000             🧑  作者: Mango

代码示例1
static void testTriangle(Shape s) {
    switch (s) {
        case Triangle t && (t.calculateArea() > 100) ->
            System.out.println("Large triangle");
        case Triangle t ->
            System.out.println("Small triangle");
        default ->
            System.out.println("Non-triangle");
    }
}