Java

Java

By DeepSource

Unnecessary imports detected JAVA-W1069

Anti-pattern

Unused imports should be removed from all source files.

If a type is never used, there is no point in importing it in a class. Furthermore, if the imported types are in the same package, they do not need to be explicitly imported. Such imports should be removed from source files. This helps readability and also prevents potential name clashes in the source file.

Bad Practice

import java.io.File;

// ...rest of the source that never uses `java.io.File`

Recommended

Just remove unused imports. Most modern IDEs provide handy shortcuts for that. If that's not an option for you, consider removing them manually.

References