I'm discovering JShell and I discovered the imports added in by default:
jshell> /imports
| import java.io.*
| import java.math.*
| import java.net.*
| import java.nio.file.*
| import java.util.*
| import java.util.concurrent.*
| import java.util.function.*
| import java.util.prefs.*
| import java.util.regex.*
| import java.util.stream.*
After doing that I added my own import using the following command:
import java.lang.Math
Is there a way to remove the latter import without killing the active session/restarting?
I've tried to issue the /edit
command, remove the import, click accept and click exit, but that didn't do the trick.
As stated in the comments, /reset
removes the import, but it also removes anything else previously input in the session. Is there a specific way to ONLY remove the import statement?
After some searching, I managed to find a solution. It's a combination of /list
(to know which line to remove) and /drop
.
/drop [name[ name...]|id[ id...]]
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.
jshell> import java.lang.Math
jshell> /list
1 : import java.lang.Math;
jshell> /drop 1
jshell> /imports
| import java.io.*
| import java.math.*
| import java.net.*
| import java.nio.file.*
| import java.util.*
| import java.util.concurrent.*
| import java.util.function.*
| import java.util.prefs.*
| import java.util.regex.*
| import java.util.stream.*