Switch expressions in statements appear to work fine, but they are not recognized as expressions. For example:
jshell> switch (day) {
...> case MONDAY, FRIDAY, SUNDAY -> 6;
...> case TUESDAY -> 7;
...> case THURSDAY, SATURDAY -> 8;
...> case WEDNESDAY -> 9;
...> }
| Error:
| not a statement
| case MONDAY, FRIDAY, SUNDAY -> 6;
| ^
| Error:
| not a statement
| case TUESDAY -> 7;
| ^
| Error:
| not a statement
| case THURSDAY, SATURDAY -> 8;
| ^
| Error:
| not a statement
| case WEDNESDAY -> 9;
| ^
This is due to "switch" triggering the statement path of code analysis and parsing.
Completion needs to be addressed as well. For example,
switch (day) {
case MONDAY, FRIDAY, SUNDAY -> 6;
case TUESDAY -> 7;
case WEDNESDAY -> 9;
case THURSDAY, SATURDAY -> 8;
} + 100
does not include the "+ 100". This may be hard to address.
-Robert
jshell> switch (day) {
...> case MONDAY, FRIDAY, SUNDAY -> 6;
...> case TUESDAY -> 7;
...> case THURSDAY, SATURDAY -> 8;
...> case WEDNESDAY -> 9;
...> }
| Error:
| not a statement
| case MONDAY, FRIDAY, SUNDAY -> 6;
| ^
| Error:
| not a statement
| case TUESDAY -> 7;
| ^
| Error:
| not a statement
| case THURSDAY, SATURDAY -> 8;
| ^
| Error:
| not a statement
| case WEDNESDAY -> 9;
| ^
This is due to "switch" triggering the statement path of code analysis and parsing.
Completion needs to be addressed as well. For example,
switch (day) {
case MONDAY, FRIDAY, SUNDAY -> 6;
case TUESDAY -> 7;
case WEDNESDAY -> 9;
case THURSDAY, SATURDAY -> 8;
} + 100
does not include the "+ 100". This may be hard to address.
-Robert
- relates to
-
JDK-8206986 Compiler support for Switch Expressions (Preview)
- Resolved
-
JDK-8192963 JEP 325: Switch Expressions (Preview)
- Closed