[英]How do I stop wildcard Java package imports in IntelliJ
On IntelliJ Java IDE when I import a class using the keyboard shortcut or take the suggested import, IntelliJ imports the whole package, eg在 IntelliJ Java IDE 上,当我使用键盘快捷键导入类或采用建议的导入时,IntelliJ 会导入整个包,例如
public static void main(String[] args) {
List list = new LinkedList();
}
would result in this import line将导致此导入行
java.util.*;
I prefer the IDE to not do a package level import and import explicit classes.我更喜欢 IDE 不执行包级导入和导入显式类。 I want to set this at the global level, so I don't have to deal with this at each project.我想在全局级别设置它,所以我不必在每个项目中都处理这个。 Is there any way to do this?有没有办法做到这一点?
I am on IntelliJ 13.0.2 on Mac OS X 10.8.5我在 Mac OS X 10.8.5 上使用 IntelliJ 13.0.2
Thanks谢谢
Open up preferences and search for "import".打开首选项并搜索“导入”。 This will narrow down the list you need to look through.这将缩小您需要查看的列表。 The screen shot shows the options for when to use single imports vs * (you can see I don't like star imports).屏幕截图显示了何时使用单一导入与 * 的选项(您可以看到我不喜欢星形导入)。
under File
menu在File
菜单下
select Settings
(ctrl+alt+s)选择Settings
(ctrl+alt+s)
select Code Style
选择Code Style
select Java
选择Java
select Imports
tab选择Imports
选项卡
under General
the check box Use single class import
will determine whether packages or classes will be imported.在General
下的Use single class import
复选框将决定是否Use single class import
包或类。
the Use fully qualified class names
check box will not use imports rather it will insert full class names directly into the code. Use fully qualified class names
复选框不会使用导入,而是将完整的类名直接插入到代码中。
请检查您是否在“设置→编辑器→自动导入”下有自动导入取消自动导入自动导入设置
I had the same issue.我遇到过同样的问题。 But the following process fixed my problem.但是以下过程解决了我的问题。
Press key combination ctrl+alt+O
, then only the needed packages will be added.按组合键ctrl+alt+O
,然后只添加需要的包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.