Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java pattern matching

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");
    }
}
Source by openjdk.java.net #
 
PREVIOUS NEXT
Tagged: #Java #pattern #matching
ADD COMMENT
Topic
Name
1+8 =