Surprising error message about a constant expression:
jshell> final int x = 1;
x ==> 1
jshell> switch (x) { case x:}
| Error:
| constant expression required
| switch (x) { case x:}
| ^
jshell> void test() { final int y = 2; switch (y) { case y:}}
| created method test()
jshell> test()
Per JLS 4.12.4, both 'x' and 'y' are constant variables, so should be allowed as switch labels. (Requirements: final, primitive type or string, initialized with a constant expression.)
If possible, the translation scheme used by JShell should be updated so that javac will see 'x' as a constant variable.
jshell> final int x = 1;
x ==> 1
jshell> switch (x) { case x:}
| Error:
| constant expression required
| switch (x) { case x:}
| ^
jshell> void test() { final int y = 2; switch (y) { case y:}}
| created method test()
jshell> test()
Per JLS 4.12.4, both 'x' and 'y' are constant variables, so should be allowed as switch labels. (Requirements: final, primitive type or string, initialized with a constant expression.)
If possible, the translation scheme used by JShell should be updated so that javac will see 'x' as a constant variable.