Using OpenJDK 14.0.1
public class Example {
private String test(final ExampleEnum ee) {
return switch (ee) {
case Value -> null;
};
}
}
public enum ExampleEnum {
Value;
public enum InnerEnum {
}
}
Compilation fails with "the switch expression does not cover all possible input values". If I remove InnerEnum
from ExampleEnum
the code compiles. Why does the presence of this inner enum cause the switch expression to fail? Is there a logical explanation or a compiler bug?
You need add default case, like this:
public class Example {
private String test(final ExampleEnum ee) {
return switch (ee) {
case Value -> null;
default -> throw new IllegalStateException("Unexpected value");
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With