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.*;
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.
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.
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.
To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.
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.
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