52 lines
1.0 KiB
Java
52 lines
1.0 KiB
Java
import java.lang.Integer;
|
|
import java.lang.Boolean;
|
|
import java.lang.String;
|
|
import java.lang.Object;
|
|
|
|
class SwitchStatement {
|
|
|
|
switchStandard(){
|
|
str = "SwitchMe";
|
|
switch(str){
|
|
case String s: return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
switchInteger(){
|
|
i = 5;
|
|
switch(i){
|
|
case Integer j:
|
|
case String s: i = 6; break;
|
|
default: i = 0; break;
|
|
}
|
|
return (i==0);
|
|
}
|
|
|
|
guardedPattern(){
|
|
var i = 1;
|
|
switch(i){
|
|
case Integer j && j == 1: return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
record Coordinates(double x, double y) {}
|
|
|
|
recordPattern(Object obj){
|
|
switch(obj){
|
|
case Coordinates(double lat, double lon): return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
record SwitchExpression(int x, int y){
|
|
|
|
boolean switchStandard(str){
|
|
return switch(str){
|
|
case String s -> yield true;
|
|
default -> yield false;
|
|
};
|
|
}
|
|
} |