class X {
int switchTest1(Object obj) {
return switch (obj) {
case (String s) -> 1;
case Integer i && predicate() -> 2;
case Integer i -> 3;
case default -> 4;
case null -> 10;
case Point() -> 5;
case Point(double x, double y) -> 6;
case Point() point -> 7;
case Point(double x, double y) point -> 8;
};
}
int switchTest2(int i) {
return switch (i) {
case Integer integer -> "int";
case Object obj -> "Object";
default -> "not ok";
};
}
void switchTest3(Point extends String> point1, Point super String> point2) {
switch (point1) {
case Point>() -> {}
}
switch (point1) {
case Point>() point -> {}
}
switch (point1) {
case Point extends String>() -> {}
}
switch (point1) {
case Point extends String>() point -> {}
}
switch (point2) {
case Point super String>() -> {}
}
switch (point2) {
case Point super String>() point -> {}
}
}
int instanceofTest(Object obj) {
if (obj instanceof (Integer i && predicate())) {
return 1;
}
if (obj instanceof (String s)) {
return 3;
}
return 2;
}
void unconditionalGuardAndDefault(Object obj) {
switch (obj) {
case Object o when true -> {}
default -> {}
}
}
native static boolean predicate();
}