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.
4 Answers. Show activity on this post. Disable File | Settings | Editor | General | Auto Import | Optimize imports on the fly. Normally you don't need to add imports manually, IDEA does it for you.
The main drawback of using wildcard imports in Java is possible naming conflicts.
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
You can set this setting here.
In IDEA 14+ the sequence is:
Settings
> Editor
> Code Style
> Java
> Imports
> Class count to use import with '*'
In older version of IDEA:
Settings
-> Java
-> Code Style
-> Imports
-> Class count to use import with '*'
The feature can not be disabled. You need to set it to a high value, e.g. 99.
In 2016.1.1 version
You should also remove the lines under Packages to Use Import with '*'
,
e.g. import javax.*;
IntelliJ IDEA:
14 & 15 & 16 EAP
File > Settings... > Editor > Code Style > Java > Imports
> in General
area add a big number for Class count to use import with '*':
/ Names count to use static import with '*':
IntelliJ IDEA:
12 & 13
File > Settings... > Code Style > Java > Imports
> in General
area add a big number for Class count to use import with '*':
P.S.: Java
is after Code Style
in the path.
And you also have to remove package names from the "Packages to use import with *" list box just below the "Class count to use import with " text boxes. Swing and AWT are there by default I think. I still was having import javax.swing.; added even though I had the class count set to 999. I used the minus sign button to remove Swing and Awt from the box and then it worked.
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