Pretty interesting, seems to only happen when the expression is assigned to a variable that was already declared.
public void test1(int y) {
int x =
switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}
public void test2(int y) {
int x;
x = switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();};
}
What did you want to happen?
Probably this?
public void test2(int y) {
int x;
x = switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}
What happened?
Pretty interesting, seems to only happen when the expression is assigned to a variable that was already declared.
What did you want to happen?
Probably this?