JShell: representation of array values

Cay Horstmann cay at horstmann.com
Thu Sep 22 03:16:26 UTC 2016


Hah, that's what I said last Java One :-)

Yes, you definitely want to do this. I've used jshell extensively for 
presentations the last year, and it was always a distraction to have to 
add Arrays.toString.

I think there is some value of seeing the actual toString output in 
addition to the useful output when feedback is verbose. Some variation of

$2 ==> String[3] { "hi", "low", null } ([Ljava.lang.String;@ae45eb6)

Cheers,

Cay

Le 09/21/2016 à 06:16 PM, Robert Field a écrit :
> JavaOne demos made it clear we need a friendlier representation of array
> values.
>
> Current --
>
> jshell> new String[] { "hi", "low", null }
> $2 ==> [Ljava.lang.String;@ae45eb6
>
> jshell> new char[] { 'a', 34, 77 }
> $3 ==> [C at 27efef64
>
> I'm proposing this --
>
> jshell> new int[4]
> $1 ==> int[4] { 0, 0, 0, 0 }
>
> jshell> new int[0]
> $2 ==> int[0] {  }
>
> jshell> new String[] { "hi", "low", null }
> $3 ==> String[3] { "hi", "low", null }
>
> jshell> new char[] { 'a', 34, 77 }
> $4 ==> char[3] { 'a', '"', 'M' }
>
> jshell> new int[][] { new int[] {44, 55}, new int[] {88,99}}
> $5 ==> int[][2] { int[2] { 44, 55 }, int[2] { 88, 99 } }
>
> jshell> new Object[] { "howdy", new int[] { 33, 44, 55 }, new String[] {
> "up", "down" }}
> $6 ==> Object[3] { "howdy", int[3] { 33, 44, 55 }, String[2] { "up",
> "down" } }
>
> jshell> new int[100000]
> $7 ==> int[100000] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0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