According to the JLS 15.29, a simple name that refers to a constant variable is a constant expression, and thus can appear as a case constant.
This is handled correctly by javac:
```
> % cat ConstantExpressionBug.java
public void main() {
final byte constant = 42;
Byte b = 42;
switch(b) { case constant: IO.println("match");}
}
> % java ConstantExpressionBug.java
match
```
whereas jshell reports an error:
```
> % jshell
| Welcome to JShell -- Version 25
| For an introduction type: /help intro
jshell> final byte constant = 42;
...> Byte b = 42;
...> switch(b) { case constant: IO.println("match");}
constant ==> 42
b ==> 42
| Error:
| constant expression required
| switch(b) { case constant: IO.println("match");}
| ^------^
jshell>
```
This is handled correctly by javac:
```
> % cat ConstantExpressionBug.java
public void main() {
final byte constant = 42;
Byte b = 42;
switch(b) { case constant: IO.println("match");}
}
> % java ConstantExpressionBug.java
match
```
whereas jshell reports an error:
```
> % jshell
| Welcome to JShell -- Version 25
| For an introduction type: /help intro
jshell> final byte constant = 42;
...> Byte b = 42;
...> switch(b) { case constant: IO.println("match");}
constant ==> 42
b ==> 42
| Error:
| constant expression required
| switch(b) { case constant: IO.println("match");}
| ^------^
jshell>
```
- relates to
-
JDK-8353831 jshell wrong propagation of constant variable
-
- Open
-