Turn off Wildcard imports?

Is there a way to turn off wildcard import like "import javax.persistence.*;" ?

Intellij 12.1.4 usually imports exactly the class I need, for example:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Table;



But at some point it replaces all the individual import statements with:


import javax.persistence.*;


Is this behavior controlled by a setting anywhere?
4

File > Settings > Project Settings > Code Style > Java > Imports > General > Class count to use import with '*'

In The settings dialog you can also search/filter - see field in the top left.

7

Thanks, that's exactly what I needed!

0

In IDEA Ultimate 2020.2 the setting is under File > Settings > Editor > Java > General > Class count to use import with '*'

5

In IDEA Ultimate 2021.1.3, the setting is under

File > Settings > Editor > Code Style > Java > Imports > Class count to use import with '*' 

and

Names count to use static import with'*'

fields (as stated in https://www.jetbrains.com/help/idea/creating-and-optimizing-imports.html#disable-wildcard-imports).

 

1

For the notice, there's also 2 hardcoded exceptions (awt & swing) that'll get through the configuration mentioned above. They're basically at the same path as the wildcard count definition, but just below on the same tab, in the " Packages to use import with '*' " section. Remove them and it'll be fine.

On osx, the configuration tab would be at:

Intellij IDEA > Preferences > Editor > Code Style > Java > Imports
2

请先登录再写评论。