5

When I enter an expression in JShell (9.0.1) it comes back with:

$22 -> <value>

Where does the 22 come from and what's happened to $1 to $21? (They are undefined.)

I seem to vaguely remember (when I started with Java 9.0) that the variables started with $1, which made more sense. Now, with 9.0.1,they all start with $22. Why?

Naman
  • 27,789
  • 26
  • 218
  • 353
DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42

1 Answers1

4

They are there, just do a

/list

to find the list of all. They are there because you seem to have already consumed 1 to 21[21 snippets/statements] until you reached the $22 -> <value> snippet.

Trying to /reset and then adding snippet should set you back :-

jshell> 0+1
$1 ==> 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 2
    Thanks! I now realise the $1 to $21 are the printing methods implicitly created when I start jshell with the command line `jshell PRINTING`. – DodgyCodeException Nov 30 '17 at 12:53
  • @DodgyCodeException Indeed that's what I was assuming when I wrote *already consumed.* – Naman Nov 30 '17 at 12:53