Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Android Studio delete wildcard imports with the "Optimize imports on the fly" option

How can I prevent Android Studio to delete the imports with a wildcard if with the Editor > General > Auto Import > Optimize imports on the fly option is enabled?

In example with this option all my tests get the junit.Assert import deleted before I can use it

import static org.junit.Assert.*;
like image 927
Addev Avatar asked Oct 02 '15 11:10

Addev


People also ask

Why should we avoid wildcard imports?

Wildcard imports help us avoid a long list of imports in our code. Therefore, this impacts the readability of code as the reader may have to scroll a lot in every source code file before reaching the code that shows the logic.

How do I disable wildcard imports in IntelliJ?

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.

How do I disable optimize imports in IntelliJ?

5 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.

How do you optimize imports?

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.


1 Answers

Although wildcard imports are not recommended, you can use it if you modify the settings in the Editor > Code Style > Java > Imports Just set the Class Count value to 2 or 3.

Imports

like image 197
brwngrldev Avatar answered Sep 19 '22 15:09

brwngrldev