Skip to content

Instantly share code, notes, and snippets.

jshell> List<String> list = #[ "a", "b", "c" ]
jshell> /env -class-path ~/.m2/repository/com/google/guava/guava/23.0/guava-23.0.jar
| Setting new options and restoring state.
jshell> import com.google.common.collect.*
jshell> List<String> list = ImmutableList.of("a", "b", "c")
list ==> [a, b, c]
jshell> List<String> list = Collections.unmodifiableList(Stream.of("a", "b", "c").collect(Collectors.toList()))
list ==> [a, b, c]
jshell> List<String> list = Collections.unmodifiableList(new ArrayList<String>() {{ add("a"); add("b"); add("c"); }});
list ==> [a, b, c]
jshell> List<String> list = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("a", "b", "c")));
list ==> [a, b, c]
jshell> List<String> list = new ArrayList<String>()
list ==> []
jshell> list.add("a")
$2 ==> true
jshell> list.add("b")
$3 ==> true
jshell> list.add("c")
@mcupak
mcupak / tjug.jsh
Last active May 31, 2018 07:26
Exploring Java 9 APIs with JShell at TJUG - session notes.
HashSet<String> set = new HashSet<String>()
set.add("a")
set.add("b")
set.add("c")
Collections.unmodifiableSet(set)
1+1
int x = 1+1
System.out.println(x)
Thread.sleep(2000)
/vars
@mcupak
mcupak / fstoco.jsh
Last active October 27, 2017 02:50
Effective prototyping with Java 9 at FSTOCO 2017 - session notes.
1+1
int x = 1+1
System.out.println(x)
Thread.sleep(2000)
/vars
/types
/list
/help
HashSet<String> set = new HashSet<String>()
set.add("a")
jshell> import jdk.jshell.*
jshell> JShell js = JShell.create()
js ==> jdk.jshell.JShell@c8e4bb0
jshell> List<SnippetEvent> snippets = js.eval("1+1")
snippets ==> [SnippetEvent(snippet=Snippet:VariableKey($1)#1-1 ... ,causeSnippetnullvalue=2)]
jshell> snippets.stream().map(s -> s.value()).forEach(System.out::println)
2
jshell> /help shortcuts
|
| shortcuts
|
| Supported shortcuts include:
|
| <tab>
| After entering the first few letters of a Java identifier,
| a jshell command, or, in some cases, a jshell command argument,
| press the <tab> key to complete the input.