Skip to content

IntelliJ

Basic Setup

Code Style

Java Imports

Never Use Wildcard Imports

We want imports to be explicit and complete. For this reason, we avoid wildcard imports such as

import java.util.*;

Go to Preferences → Editor → Code Style → Java and select the tab Imports in the content area.

Check the field Use single class import and set the Class count to use import with '*' to 9999. Also set Names count to use static import with '*' to 9999:

If we now tell IntelliJ to Optimize Imports, IntelliJ will never replace imports of classes from the same package with a wildcard.

Import Layout

We want all Java source files to sort imports so that static imports are at the top, followed by java classes, javax classes, and all other classes.

Go to Preferences → Editor → Code Style → Java and select the tab Imports in the content area.

Scroll down to Import Layout. Use the up and down arrows to arrange the imports, resulting in the following layout:

With this setting, the static imports come first, followed by the imports of the java classes, the javax classes, and all other classes.


Last update: 2022-11-03