Import statements
suggest change// First java/javax packages
import java.util.ArrayList;
import javax.tools.JavaCompiler;
// Then third party libraries
import com.fasterxml.jackson.annotation.JsonProperty;
// Then project imports
import com.example.my.project.ClassA;
import com.example.my.project.ClassB;
// Then static imports (in the same order as above)
import static java.util.stream.Collectors.toList;
- Import statements should be sorted…
- …primarily by non-static / static with non-static imports first.
- …secondarily by package origin, in this order:
javapackagesjavaxpackages- third-party packages (for example
org.xmlorcom.fasterxml) - the project's own packages (for example
com.example)
package is a keyword, so it cannot appear as a package-name segment. com.sun is a JDK-internal package, not the application's own code.
- …tertiary by package and class identifier in lexicographical order
- Import statements should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line.
- No unused imports should be present.
Wildcard imports
- Wildcard imports should in general not be used.
- When importing a large number of closely-related classes (such as implementing a visitor over a tree with dozens of distinct “node” classes), a wildcard import may be used.
- In any case, no more than one wildcard import per file should be used.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents