import java.util.Random;
class SwitchExpressions {
enum E { E1, E2 }
void m(String s, Integer i) {
System.out.println(switch (new Random().nextInt()) {
default -> "whatever";
});
System.out.println(switch (new Random().nextInt()) { });
System.out.println(switch (new Random().nextInt()) {
case 0 -> throw new IllegalStateException("no args");
case 1: yield "lone";
});
System.out.println(
switch (new Object()) {
default -> "whatever";
}
);
System.out.println(switch (E.valueOf("E1")) {
case null -> 0;
case E1 -> 1;
case E2 -> 2;
});
System.out.println(switch (E.valueOf("E1")) {
case E.E1 -> 1;
case E2 -> 2;
case 1 -> 1;
});
System.out.println(switch (new Random().nextInt()) {
default -> -1;
case 1 -> 1;
default -> 0;
});
System.out.println(switch (new Random().nextInt()) {
case 1 -> 1;
});
System.out.println(switch (E.valueOf("E1")) {
case E1 -> 1;
});
System.out.println(switch (s) {
case "blah blah blah" -> 1;
});
System.out.println(switch (i) {
case 42 -> 1;
});
System.out.println(switch (s) {});
System.out.println(switch (i) {});
System.out.println(switch (E.valueOf("E1")) {
case E1 -> 1;
case E2 -> 2;
});
lab: while (true) {
switch (new Random().nextInt()) {
case -1: return;
case -2: continue lab;
default: break lab;
}
System.out.println(switch (new Random().nextInt()) {
case -1: return;
case -2: continue lab;
case -3: continue;
default: break lab;
});
}
}
enum Empty {}
boolean testEmpty(Empty e) {
return switch (e) {};
}
byte assignability(String s) {
return switch(s) {
default -> 42;
};
}
}