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

JShell API: special printing for arrays, Collection, Strings

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • 9
    • 9
    • tools
    • None

      The toString() method on arrays is generally unhelpful (inherited from Object.) Since jshell is a read-eval-PRINT loop, it might be nice to print the result of array-valued expressions in a friendlier manner, such as by using Arrays.toString(array) instead of array.toString(). (Might want to limit this to arrays of below a certain length. (Might want to allow that limit to be set by preferences.))

      So we'd get

      [ 1, 2, 3 ]

      instead of

      [I@2048230

      -Brian

      Yes, please limit (i had also this noted down for another review round). It would be aesthetically pleasing to align the output to fit into an equal number of R rows for Math.min(R * C, MAX_CHARS);

      Paul.

      If arrays are big, how about printing "the first few" and "the last few", separate by "...", as in

      [ 1, 2, 3, ..., 98, 99, 100 ]

      -- Jon

      Same applies to Collection as well (not sure we can always do the same for Iterable given it might be traversable once only in some rare cases).

      I think there should also be truncation for toString beyond a certain length e.g.: it could be something like (aligned to the columns for a certain number of rows):

      -> Stream.generate(() -> "A").limit(10000).collect(Collectors.joining(""));
      | String $1 = “AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."

      -Paul

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

              Created:
              Updated:
              Resolved: