Is there a way to tell IntelliJ never to use wildcard imports? Under 'Settings > Code Style > Imports', I can see that you can specify the 'class count' prior to IntelliJ using wildcard imports. However, if I never want to use wildcard imports can I turn this functionality off?
I have tried putting -1 or leaving the field blank but that just tells IntelliJ to always use wildcard imports. Obviously a not-so-nice solution would be to put a ridiculously high number so that you never encounter wildcard imports but I was hoping there was a nicer way to just turn it off.
Disable wildcard importsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.
The main drawback of using wildcard imports in Java is possible naming conflicts. Let's assume that we have developed an ArrayList class ourself which implements the java. util. List interface.
In fact, the book recommends using wildcard imports when using multiple classes from the same source. In other words, when we import two or more classes imported from a package, it's better to import the whole package.
After this, your configuration should look like:
(On IntelliJ IDEA 13.x, 14.x, 15.x, 2016.x, 2017.x)
It's obvious why you'd want to disable this: To force IntelliJ to include each and every import individually. It makes it easier for people to figure out exactly where classes you're using come from.
Click on the Settings "wrench" icon on the toolbar, open "Imports" under "Code Style", and check the "Use single class import" selection. You can also completely remove entries under "Packages to use import with *
", or specify a threshold value that only uses the "*
" when the individual classes from a package exceeds that threshold.
Update: in IDEA 13 "Use single class import" does not prevent wildcard imports. The solution is to go to Preferences
(⌘ + , on macOS / Ctrl + Alt + S on Windows and Linux) > Editor > Code Style > Java > Imports tab
set Class count to use import with '*'
and Names count to use static import with '*'
to a higher value. Any value over 99 seems to work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With