This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> List<String> list = #[ "a", "b", "c" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> List<String> list = Collections.unmodifiableList(Stream.of("a", "b", "c").collect(Collectors.toList())) | |
| list ==> [a, b, c] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> List<String> list = Collections.unmodifiableList(new ArrayList<String>() {{ add("a"); add("b"); add("c"); }}); | |
| list ==> [a, b, c] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> List<String> list = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("a", "b", "c"))); | |
| list ==> [a, b, c] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> List<String> list = new ArrayList<String>() | |
| list ==> [] | |
| jshell> list.add("a") | |
| $2 ==> true | |
| jshell> list.add("b") | |
| $3 ==> true | |
| jshell> list.add("c") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |