Home > Java > javaTutorial > body text

How to reset JShell session in Java 9?

WBOY
Release: 2023-08-19 17:49:16
forward
748 people have browsed it

如何在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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!