jshell drop jshell drop means changing the status of snippets to DROPPED
and making them inactive (so they are no more active and you can not use them until you create them again)
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.
DROPPED
The snippet is inactive because of an explicit call to the JShell.drop(Snippet).
In the below code you have two snippets
and by using drop
you made them inactive
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
In the same way you can also see all active and dropped snippets in jshell
console
/list [option]
Displays a list of snippets and their ID. If no option is entered, then all active snippets are displayed, but startup snippets aren’t.
/list -all
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.
Is there something in JShell that goes back one step?
In jshell each input is exactly one snippet so there is no way to rollback of snippets.
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).