I'm developing with Java 17 in IntelliJ IDEA 2022.2.
In some cases 'switch' expression does not cover all possible input values
is shown, but in some not. I'd like to figure out why.
Let's assume that entityType
is an enum with 3 values and I'm adding 4th one TYPE_D
. So I expect to see 'switch' expression does not cover all possible input values
errors where I use this enum in switch
.
When it is shown:
public Map<String, String> getRecordDetails() {
return switch (entityType) {
case TYPE_A -> Map.of("A","A");
case TYPE_B -> Map.of("B","B");
case TYPE_C -> Map.of("C","C");
};
}
When it's not shown:
public String getRecordDetails() {
StringBuilder stringBuilder = new StringBuilder();
switch (entityType) {
case TYPE_A -> stringBuilder.append("A");
case TYPE_B -> stringBuilder.append("B");
case TYPE_C -> stringBuilder.append("C");
};
return stringBuilder.toString();
}
I see it is related when I do return of switch
case, but why it is not shown when I have switch case inside of function's code?
default -> Map.of();
– Winglet