Is there a way to remove imports in JShell?

♀尐吖头ヾ 提交于 2019-12-07 16:48:41

问题


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?


回答1:


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.*


来源:https://stackoverflow.com/questions/46808748/is-there-a-way-to-remove-imports-in-jshell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!