JShell How to find the type of Variable or Result

Just figured out it can be solved by setting the feedback mode.

/set feedback verbose

Reference https://docs.oracle.com/javase/9/jshell/feedback-modes.htm

Now can easily find the type of an expression or variable in the response.

jshell> 5<<-1
$15 ==> -2147483648
|  created scratch variable $15 : int

The mode can be reset by using the command

/set feedback normal

and the current mode can be queried by simply calling

/set feedback

I found an explicit way to do this (I'm running with JDK11) using the /vars command

|  Welcome to JShell -- Version 11
|  For an introduction type: /help intro

jshell> 5<<-1
$1 ==> -2147483648

jshell> /vars
|    int $1 = -2147483648

Tags:

Java

Jshell