如何在 IntelliJ 中停止通配符 Java 包导入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26225989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:02:15  来源:igfitidea点击:

How do I stop wildcard Java package imports in IntelliJ

javaintellij-ideaimportide

提问by Vijay Kumar

On IntelliJ Java IDE when I import a class using the keyboard shortcut or take the suggested import, IntelliJ imports the whole package, e.g.

在 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. 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?

我更喜欢 IDE 不执行包级导入和导入显式类。我想在全局级别设置它,所以我不必在每个项目中都处理这个。有没有办法做到这一点?

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

谢谢

采纳答案by Tracy Snell

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

打开首选项并搜索“导入”。这将缩小您需要查看的列表。屏幕截图显示了何时使用单一导入与 * 的选项(您可以看到我不喜欢星形导入)。

enter image description here

在此处输入图片说明

回答by BevynQ

under Filemenu

File菜单下

select Settings(ctrl+alt+s)

选择Settings(ctrl+alt+s)

select Code Style

选择 Code Style

select Java

选择 Java

select Importstab

选择Imports标签

under Generalthe check box Use single class importwill determine whether packages or classes will be imported.

General复选框下Use single class import将决定是否导入包或类。

the Use fully qualified class namescheck box will not use imports rather it will insert full class names directly into the code.

Use fully qualified class names复选框不会使用导入,而是将完整的类名直接插入到代码中。

回答by Dinusha

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,然后只添加需要的包。

回答by Jin Thakur

Please check if you have autoimport cancel autoimport auto-import settings under "Settings → Editor → Auto Import

请检查您是否在“设置→编辑器→自动导入”下有自动导入取消自动导入自动导入设置