How to Avoid Wildcard Imports in IntelliJ for Java
How do we avoid using wildcard imports in IntelliJ completely?
I never use wildcard imports in Java and try to always include imports individually, but IntelliJ frequently optimizes my imports to use wildcards (collapsing imports to use
* is an optimization by default).
We would think IntelliJ natively supports a toggle for this feature, but unfortunately, that’s not the case.
Here’s how we might fix this.
Avoid wildcard imports in Preferences
- Go to
Son Windows and Linux
- Go to
Importstab in the panel
- Set these values in
Use single class import: checked
Class count to use import with '*': an absurdly large number (i.e. over
Names count to use static import with '*': the same absurdly large number
- Ensure the
Packages to use import with '*'section is empty
OK, then you should be on your way.
Use Find Action to avoid wildcards
If we don’t want to navigate through our
Preferences, we can use the
Find Action feature in IntelliJ.
Aon Windows and Linux
- Begin typing
Class count to use import with '*'
Enterwhen the option appears
- Fill in the same values as in the section above