Search code examples
javaintellij-idea

Preventing IntelliJ from suggesting ".*" form when importing classes


I'm using IntelliJ IDEA as my Java IDE, and I often use the ALT + ENTER keyboard shortcut to import classes quickly. However, IntelliJ frequently suggests using the ".*" form, which imports all classes from a package. While this might be useful in some cases, I prefer to import only the specific classes I need to avoid cluttering my imports and potential naming conflicts.

Is there a way to prevent IntelliJ IDEA from suggesting the ".*" form when importing classes using the ALT + ENTER keyboard shortcut? I'd still like to use the auto-import functionality, but I want to have more control over the classes being imported.

Any help would be appreciated. Thanks!


Solution

  • I also do not like asterisk imports. Here is my method of how I avoid them. I go to the IntelliJ Idea "Settings", then I go "Editor -> Code Style -> Java". There you will see a lot of tabs and settings. You're interested in "Imports". Here I set "Class count to use import with '*'" to something big like 1000. enter image description here I'm using IntelliJ Idea on MacOS. If you're using different version, look around, you still have this "Code Style" settings somewhere. I would also like to know a better way to do that, but if no one will suggest anything better, you may use my "hack", it works.