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

JShell: incorrect printing of multidemensional arrays

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • tools
    • None
    • b151
    • Verified

      I'm doing some spec work with array types, and noticed what's probably a bug in the printing of arrays by JShell:

      jshell> int[][] arr = new int[3][1]
      arr ==> int[][3] { int[1] { 0 }, int[1] { 0 }, int[1] { 0 } }

      jshell> int[][] arr = new int[3][]
      arr ==> int[][3] { null, null, null }

      Looks like the format here is
      <component-type>[<length>] { <components> }

      However, as you can see in the initialization expressions, this gets the dimensions backwards compared to the way the language likes to treat them. I suggest a different, more complex format, that aligns better with the language's usage:

      <element-type>[<length>]<extra-dims> { <components> }

      This would look like:

      jshell> int[][] arr = new int[3][1]
      arr ==> int[3][] { int[1] { 0 }, int[1] { 0 }, int[1] { 0 } }

      jshell> int[][] arr = new int[3][]
      arr ==> int[3][] { null, null, null }

      —Dan

            rfield Robert Field (Inactive)
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: