Since Checkstyle 3.0
Checks for redundant import statements. An import statement is considered redundant if:
java.lang
package, e.g. importing java.lang.String
.
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="RedundantImport"/> </module> </module>
Example:
package Test; import static Test.MyClass.*; // OK, static import import static java.lang.Integer.MAX_VALUE; // OK, static import import Test.MyClass; // violation, imported from the same package as the current package import java.lang.String; // violation, the class imported is from the 'java.lang' package import java.util.Scanner; // OK import java.util.Scanner; // violation, it is a duplicate of another import public class MyClass{ };
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.imports