IntelliJ:永远不要使用通配符导入 [英] IntelliJ: Never use wildcard imports

查看:1882
本文介绍了IntelliJ:永远不要使用通配符导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉IntelliJ永远不要使用通配符导入?
在设置>代码样式>导入下,我可以看到您可以使用通配符导入在IntelliJ之前指定类计数。但是,如果我从不想使用通配符导入,我可以关闭此功能吗?

Is there a way to tell IntelliJ never to use wildcard imports? Under 'Settings > Code Style > Imports', I can see that you can specify the 'class count' prior to IntelliJ using wildcard imports. However, if I never want to use wildcard imports can I turn this functionality off?

我试过把-1放在空白处,但这只是告诉IntelliJ总是使用通配符导入。显然,一个不太好的解决方案是设置一个非常高的数字,以便你永远不会遇到通配符导入,但我希望有一个更好的方法来关闭它。

I have tried putting -1 or leaving the field blank but that just tells IntelliJ to always use wildcard imports. Obviously a not-so-nice solution would be to put a ridiculously high number so that you never encounter wildcard imports but I was hoping there was a nicer way to just turn it off.

推荐答案

很明显,为什么你要禁用它:强制IntelliJ单独包含每个导入。它使人们更容易弄清楚你正在使用的课程来自哪里。

It's obvious why you'd want to disable this: To force IntelliJ to include each and every import individually. It makes it easier for people to figure out exactly where classes you're using come from.

点击工具栏上的设置扳手图标,打开导入在代码样式下,选中使用单一类导入选项。您还可以完全删除使用 * 导入的包下的条目,或指定仅使用 * 当包中的各个类超过该阈值时。

Click on the Settings "wrench" icon on the toolbar, open "Imports" under "Code Style", and check the "Use single class import" selection. You can also completely remove entries under "Packages to use import with *", or specify a threshold value that only uses the "*" when the individual classes from a package exceeds that threshold.

更新:在IDEA 13中使用单一类导入不会防止通配符导入。解决方案是转到首选项 + 在macOS / Ctrl +上Windows上的 Alt + S >编辑>代码风格> Java>导入选项卡设置类计数使用带'*'的导入名称计数使用静态导入带'*'更高的价值。任何超过99的值似乎都能正常工作。

Update: in IDEA 13 "Use single class import" does not prevent wildcard imports. The solution is to go to Preferences ( + , on macOS / Ctrl + Alt + S on Windows) > Editor > Code Style > Java > Imports tab set Class count to use import with '*' and Names count to use static import with '*' to a higher value. Any value over 99 seems to work fine.

这篇关于IntelliJ:永远不要使用通配符导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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