Home  >  Article  >  Java  >  How to reset JShell session in Java 9?

How to reset JShell session in Java 9?

WBOY
WBOYforward
2023-08-19 17:49:16750browse

如何在Java 9中重置JShell会话?

Java 9 introduced JShell which allows us to evaluate code snippets such as statements, statements and expression.

During a JShell session, we need to reset JShell without closing and reopening it, then we can use the internal command: "/reset". By using this command, the code entered in the current session will be erased. This is useful when we want to test new classes, create new variables, etc. while retaining the previously used names.

In the following code snippet, we have created the variables x, y and str. We can use the "/list" command to view all entered code snippets. Afterwards, we can use the "/reset" command to reset the current session.

<strong>jshell> int a = 25
a ==> 25

jshell> double y = 30
y ==> 30.0

jshell> String str = "Tutorialspoint"
str ==> "Tutorialspoint"

jshell> /list

1 : int a = 25;
2 : double y = 30;
3 : String str = "Tutorialspoint";

jshell> /reset
| Resetting state.

jshell> /list

jshell> x
|  Error:
|  cannot find symbol
|    symbol: variable x
|  x
|  ^

jshell> str
|  Error:
|  cannot find symbol
|   symbol: variable str
|  str
|  ^-^

jshell> int x = 15
x ==> 15

jshell> String str = "reset"
str ==> "reset"

jshell> /list

  1 : int x = 15;
  2 : String str = "reset";</strong>

The above is the detailed content of How to reset JShell session in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete