Jshell

A REPL

type /exit to quit

Requires Java 9+, use –class-path to add libraries to jshell to be able to create those objects.

PS C:\devtools> java -version
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)
PS C:\devtools> jshell
|  Welcome to JShell -- Version 11.0.12
|  For an introduction type: /help intro

jshell> /env --class-path c
commons-collections4-4.4-bin.zip   commons-collections4-4.4/

<press tab again to see synopsis>
jshell> /env --class-path commons-collections4-4.4/c
commons-collections4-4.4-javadoc.jar        commons-collections4-4.4-sources.jar
commons-collections4-4.4-test-sources.jar   commons-collections4-4.4-tests.jar
commons-collections4-4.4.jar

<press tab again to see synopsis>
jshell> /env --class-path commons-collections4-4.4/commons-collections4-4.4.jar
|  Setting new options and restoring state.

jshel

jshell> import org.apache.commons.collections4.*

jshell> Bag b = new Ha
HashMap(     HashSet(     Hashtable(
jshell> Bag b = new HashBag();
|  Error:
|  cannot find symbol
|    symbol:   class HashBag
|  Bag b = new HashBag();
|              ^-----^

jshell> import org.apache.commons.collections4.bag.HashBag

jshell> Bag b = new HashBag();
b ==> []

jshell> b.add
add(      addAll(
jshell> b.add(
b

Signatures:
boolean Bag<E>.add(E)
boolean Bag<E>.add(E, int)

<press tab again to see documentation>
jshell> b.add("FOO", 10);
|  Warning:
|  unchecked call to add(E,int) as a member of the raw type org.apache.commons.collections4.Bag
|  b.add("FOO", 10);
|  ^--------------^
$4 ==> true

/save filename.jsh to save commands in a file for later use

/open filename.jsh to open a local file again

/vars to display all the variables in scope

Leave a comment

Your email address will not be published. Required fields are marked *