简体   繁体   English

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

[英]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 menuFile菜单下

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复选框不会使用导入,而是将完整的类名直接插入到代码中。

IntelliJ version 2020.2.3 (October built) IntelliJ 2020.2.3版(10月建)

Preferences > Editor > CodeStyle > Java in the "General" tab check "Use Single Class import" check "Use fully qualified class names"首选项> 编辑器> CodeStyle > Java 在“常规”选项卡中选中“使用单个类导入”选中“使用完全限定的类名”

在此处输入图片说明

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

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.

相关问题 自动将通配符导入重构为 IntelliJ 中的显式导入(适用于 Scala/Java) - Automatically refactor wildcard imports into explicit imports in IntelliJ (for Scala/Java) IntelliJ:永远不要使用通配符导入 - IntelliJ: Never use wildcard imports 如何在 IntelliJ 中将目录转换为 package - How do I convert a directory to a package in IntelliJ 默认从 sun 而不是 intelliJ 中的 java 包导入 - Default imports from sun instead of java package in intelliJ 在 IntelliJ 中遇到一个问题,它只接受 java 包的通配符导入,而不是 java 包中的特定类 - Encountering a Problem in IntelliJ which only accepts Wildcard Imports of java packages instead of specific Classes from java packages 禁用IntelliJ已加星标(包)导入? - Disable IntelliJ Starred (Package) Imports? 通配符导入Java和Scala中的用法 - Wildcard imports usage in Java and Scala 如何防止 openapi-generator 在 java 中使用通配符导入 - How to prevent openapi-generator from using wildcard imports in java 当我调用优化导入时,如何阻止IntelliJ导入JavaDocs中使用的类? - How do I prevent IntelliJ from importing classes used in JavaDocs when I call optimize imports? IntelliJ 运行其他类文件,我该如何停止呢? - IntelliJ Running other class files, how do I stop this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM