有没有办法删除JShell中的导入? [英] Is there a way to remove imports in JShell?

查看:79
本文介绍了有没有办法删除JShell中的导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发现JShell,并且发现了默认情况下添加的导入:

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?

我试图发出/edit命令,删除导入,单击接受",然后单击退出",但这并没有解决问题.

I've tried to issue the /edit command, remove the import, click accept and click exit, but that didn't do the trick.

如注释中所述,/reset除去导入,但也除去先前在会话中输入的任何其他内容.是否有只删除导入语句的特定方法?

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

删除代码段,使其变为非活动状态.提供名称或ID 导入,类,方法或变量.如果有多个摘要, 用空格分隔名称和ID .使用/list命令查看 代码段的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.*

这篇关于有没有办法删除JShell中的导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆