jshell

Access to “parent scope” in JShell

本小妞迷上赌 提交于 2019-12-07 01:26:37
问题 It seems, that JShell object created inside another JShell does not have access to parent's JShell scope. For instance: jshell> int x = 1; x ==> 1 jshell> x x ==> 1 jshell> jdk.jshell.JShell js = jdk.jshell.JShell.create(); js ==> jdk.jshell.JShell@1a052a00 jshell> js.eval("x"); $4 ==> [SnippetEvent(snippet=Snippet:ErroneousKey#1-x,previousStatus=NONEXISTENT,status=REJECTED,isSignatureChange=false,causeSnippetnull)] jshell> js.eval("int x = 2;"); $5 ==> [SnippetEvent(snippet=Snippet

List all active methods in jshell

纵饮孤独 提交于 2019-12-07 00:59:01
问题 is there any command available that can print all newly created methods in current jshell session? Something similar to /list but only for methods 回答1: You are looking for the command /methods -all which prints all the methods including those added when JShell was started, and methods that failed, were overwritten, or were dropped. For active methods declared by you, use it simply without any argument as : /methods 来源: https://stackoverflow.com/questions/47543272/list-all-active-methods-in

How to take user input in jshell script?

白昼怎懂夜的黑 提交于 2019-12-06 12:28:57
Question: How to take user input in jshell script ? or what I'm doing wrong? Note: I'm NOT looking how to pass arguments to jshell script . Example: For example script hello.java : Scanner in = new Scanner(System.in); System.out.print("Enter number n1: "); int n1 = in.nextInt(); System.out.print("Enter number n2: "); int n2 = in.nextInt(); System.out.println("n1 + n2 = "+ (n1 +n2)); /exit It works if I type line by line in jshell, but then I run jshell hello.java it doesn't. Throws java.util.NoSuchElementException . Output I getting: @myMint ~/Java $ jshell hello.java Enter number n1: | java

Create custom feedback mode in jshell

流过昼夜 提交于 2019-12-05 20:19:20
As from the documentation of /set feedback in jshell, there are following built-in modes: verbose, normal, concise, and silent Is it possible to create a feedback mode with the functionality of both concise and silent? Or we can change any one of the above mode? Or can we create our own custom feedback mode? You can create your own custom feedback mode using the command: /set mode <your-mode-name> -command|-quiet where the -command option indicates that you want command feedback. If you don't want commands to describe the action that occurred, then use -quiet instead of -command . If you want

jshell - unable to find printf

試著忘記壹切 提交于 2019-12-05 17:46:59
Why does my jshell instance (JDK Version 9-ea) unable to identify printf() statement ? Below is the error I observe, jshell> printf("Print number one - %d",1) | Error: | cannot find symbol | symbol: method printf(java.lang.String,int) | printf("Print number one - %d",1) | ^----^ I am able to access printf, provided I specify it in a regular way. jshell> System.out.printf("Print number one - %d",1) Print number one - 1$1 ==> java.io.PrintStream@1efbd816 Any pointers? An earlier version of JShell had a printf method pre-defined but it was removed from early access builds. You can of course

In jshell-11, why does a redeclared reference variable that resets to null still have a type?

北战南征 提交于 2019-12-05 14:15:27
问题 When redeclaring Integer 'a' in line 33, why does jshell show the reference variable as an instance of Integer (refer to lines 38 & 39)? After the redeclaration, line 34 shows that 'a' is set to null. When 'a' is declared in line 6 but not given a value, or reset to null in line 22, 'a' is not considered an instance of Integer. I would expect that when the reference variable is redeclared, since its value is null, that it would not be an instance of a type; however, that is not the case. 01:

Multiline paste in jshell

大兔子大兔子 提交于 2019-12-05 12:05:54
问题 I was trying out jshell and couldn't find option to paste multiple line expressions. Is it even possible to paste multiple lines in jshell. Similar to what scala offers with paste mode . 回答1: So if you have code like this: int c = 2; int j = 4; int x = 5; Copy and paste into jshell, only the first two statements are processed. But if you have code like this: int c = 2; int j = 4; int x = 5; And paste into jshell: jshell> int c = 2; int j = 4; int x = 5; c ==> 2 j ==> 4 x ==> 5 Even more lines

Access to “parent scope” in JShell

…衆ロ難τιáo~ 提交于 2019-12-05 06:40:34
It seems, that JShell object created inside another JShell does not have access to parent's JShell scope. For instance: jshell> int x = 1; x ==> 1 jshell> x x ==> 1 jshell> jdk.jshell.JShell js = jdk.jshell.JShell.create(); js ==> jdk.jshell.JShell@1a052a00 jshell> js.eval("x"); $4 ==> [SnippetEvent(snippet=Snippet:ErroneousKey#1-x,previousStatus=NONEXISTENT,status=REJECTED,isSignatureChange=false,causeSnippetnull)] jshell> js.eval("int x = 2;"); $5 ==> [SnippetEvent(snippet=Snippet:VariableKey(x)#2-int x = 2;,previousStatus=NONEXISTENT,status=VALID,isSignatureChange=true,causeSnippetnullvalue

Why and how do you use JShell?

一曲冷凌霜 提交于 2019-12-05 04:16:45
I went through a couple of tutorials for JShell and I still do not understand the most important part: why would I even use JShell? Here what Oracle says: "You can test individual statements, try out different variations of a method, and experiment with unfamiliar APIs within the JShell session". Yes, great, but for all those things I can just use an IDE. I do understand, that REPL should make code evaluation faster. However, testing a snippet of code in IDE in a dummy Hello World project with Sysout is for sure not slower? In fact, IDEs provide autocomplete, detect errors early and I can

Debugging with JShell

限于喜欢 提交于 2019-12-05 03:48:16
I write a Java method in JShell and now I want to debug it. I would like to set breakpoints or at least step through an execution line-by-line. Does JShell have these debugging abilities? Just to clarify further, from the JEP: The Java Shell (Read-Eval-Print Loop) itself, the Non-Goals states : Out of scope are graphical interfaces and debugger support . The JShell API is intended to allow JShell functionality in IDEs and other tools, but the jshell tool is not intended to be an IDE . There is some undocumented /debug command (Jshell in Java 11). After /help /debug command you can see: jshell>