Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8353831

jshell wrong propagation of constant variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 24
    • tools
    • None

      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;
      | ^

            abimpoudis Angelos Bimpoudis
            abimpoudis Angelos Bimpoudis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: