A narrowing primitive conversion with a constant expression is allowed in the assignment context. Two examples:
// literal
jshell> byte b = 42;
b ==> 42
// simple name that refers to a constant variable
jshell> class Test {
...> final int i = 42;
...> void test() {
...> byte b = i;
...> }
...> }
| created class Test
However, in JShell we observe the following erroneous behavior:
jshell> final int i = 42;
i ==> 42
jshell> byte b = i;
| Error:
| incompatible types: possible lossy conversion from int to byte
| byte b = i;
| ^
// literal
jshell> byte b = 42;
b ==> 42
// simple name that refers to a constant variable
jshell> class Test {
...> final int i = 42;
...> void test() {
...> byte b = i;
...> }
...> }
| created class Test
However, in JShell we observe the following erroneous behavior:
jshell> final int i = 42;
i ==> 42
jshell> byte b = i;
| Error:
| incompatible types: possible lossy conversion from int to byte
| byte b = i;
| ^