有没有办法删除 JShell 中的历史记录?
Is there any way to delete history in JShell?
在 JShell 中,是否有任何方法可以删除您执行的语句,就像它从未发生过一样?
例如,假设我们有以下代码。
JShell shell = JShell.create();
shell.eval("int x = 5;");
shell.eval("x = 7;");
JShell 中有什么东西可以后退一步吗?也就是说,类似于方法 goBackOneStep()
的东西,在执行它之后,将 x
设置回 5.
shell.goBackOneStep();
shell.eval("x") // x is evaluated to 5
我注意到 JShell API 中有一个名为 drop(Snippet)
的方法,它似乎从历史记录中删除了 Snippet
,但它没有删除 [=15= 的任何影响】 过上状态。
jshell drop jshell drop 意味着将代码片段的状态更改为 DROPPED
并使它们处于非活动状态(因此它们不再处于活动状态并且您无法使用它们,直到您再次创建它们)
Drops a snippet, making it inactive. Provide either the name or the ID of an import, class, method, or variable. For more than one snippet, separate the names and IDs with a space. Use the /list command to see the IDs of code snippets.
The snippet is inactive because of an explicit call to the JShell.drop(Snippet).
在下面的代码中你有两个 snippets
并且通过使用 drop
你使它们处于非活动状态
JShell shell = JShell.create();
shell.eval("int x = 5;");
shell.eval("x = 7;");
shell.snippets().forEach(s1->shell.drop(s1));
shell.snippets().forEach(s2->{
System.out.println(shell.status(s2)); //DROPPED
});
shell.snippets().forEach(System.out::println); //we print all active and inactive snippets
以同样的方式,您还可以在 jshell
控制台
中查看所有活动和删除的片段
/列表[选项]
Displays a list of snippets and their ID. If no option is entered, then all active snippets are displayed, but startup snippets aren’t.
/列表-全部
Displays all snippets, including startup snippets and snippets that failed, were overwritten, or were dropped. IDs that begin with s are startup snippets. IDs that begin with e are snippets that failed.
JShell 中有返回一步的东西吗?
在 jshell 中,每个输入都是一个片段,因此无法回滚片段。
The input should be exactly one complete snippet of source code, that is, one expression, statement, variable declaration, method declaration, class declaration, or import. To break arbitrary input into individual complete snippets, use SourceCodeAnalysis.analyzeCompletion(String).
在 JShell 中,是否有任何方法可以删除您执行的语句,就像它从未发生过一样?
例如,假设我们有以下代码。
JShell shell = JShell.create();
shell.eval("int x = 5;");
shell.eval("x = 7;");
JShell 中有什么东西可以后退一步吗?也就是说,类似于方法 goBackOneStep()
的东西,在执行它之后,将 x
设置回 5.
shell.goBackOneStep();
shell.eval("x") // x is evaluated to 5
我注意到 JShell API 中有一个名为 drop(Snippet)
的方法,它似乎从历史记录中删除了 Snippet
,但它没有删除 [=15= 的任何影响】 过上状态。
jshell drop jshell drop 意味着将代码片段的状态更改为 DROPPED
并使它们处于非活动状态(因此它们不再处于活动状态并且您无法使用它们,直到您再次创建它们)
Drops a snippet, making it inactive. Provide either the name or the ID of an import, class, method, or variable. For more than one snippet, separate the names and IDs with a space. Use the /list command to see the IDs of code snippets.
The snippet is inactive because of an explicit call to the JShell.drop(Snippet).
在下面的代码中你有两个 snippets
并且通过使用 drop
你使它们处于非活动状态
JShell shell = JShell.create();
shell.eval("int x = 5;");
shell.eval("x = 7;");
shell.snippets().forEach(s1->shell.drop(s1));
shell.snippets().forEach(s2->{
System.out.println(shell.status(s2)); //DROPPED
});
shell.snippets().forEach(System.out::println); //we print all active and inactive snippets
以同样的方式,您还可以在 jshell
控制台
/列表[选项]
Displays a list of snippets and their ID. If no option is entered, then all active snippets are displayed, but startup snippets aren’t.
/列表-全部
Displays all snippets, including startup snippets and snippets that failed, were overwritten, or were dropped. IDs that begin with s are startup snippets. IDs that begin with e are snippets that failed.
JShell 中有返回一步的东西吗?
在 jshell 中,每个输入都是一个片段,因此无法回滚片段。
The input should be exactly one complete snippet of source code, that is, one expression, statement, variable declaration, method declaration, class declaration, or import. To break arbitrary input into individual complete snippets, use SourceCodeAnalysis.analyzeCompletion(String).