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.
This question is related to
java
intellij-idea
settings
If you don't want to change preferences, you can optimize imports by pressing Ctrl+Option+o on Mac or Ctrl+Alt+o on Windows/Linux and this will replace all imports with single imports in current file.
Like a dum-dum I couldn't figure out why none of these answers were working for my Kotlin files for java.util.*
, so if this is happening to you then:
Preferences
> Editor
> Code Style
> **Kotlin**
> Imports
> Packages to Use Import with '*'
-> Remove 'java.util.*'
The solution above was not working for me. I had to set 'class count to use import with '*'' to a high value, e.g. 999.
If non of above works for you, then it is worth to check if you have any packages under Preference > Editor > Code Style > Java > Imports > Packages to Use Import with "*"
After this, your configuration should look like:
(On IntelliJ IDEA 13.x, 14.x, 15.x, 2016.x, 2017.x)
Shortcut doing this on Mac: Press command+Shift+A (Action) and type "class count to use import with *" Press Enter. Enter a higher number there like 999
Source: Stackoverflow.com