Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java switch class instanceof

static String formatterPatternSwitch(Object o) {
    return switch (o) {
        case Integer i -> String.format("int %d", i);
        case Long l    -> String.format("long %d", l);
        case Double d  -> String.format("double %f", d);
        case String s  -> String.format("String %s", s);
        default        -> o.toString();
    };
}
Source by blogs.oracle.com #
 
PREVIOUS NEXT
Tagged: #java #switch #class #instanceof
ADD COMMENT
Topic
Name
7+9 =