Redundant java.lang Import
ID |
java.redundant_java_lang_import |
Severity |
info |
Remediation Complexity |
auto_fix |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style, imports |
Description
Reports explicit import statements for classes in the java.lang package, which are automatically imported by the Java compiler.
Rationale
The Java Language Specification states that java.lang.* is implicitly imported in every compilation unit. Explicitly importing classes like java.lang.String, java.lang.Integer, or java.lang.Object is redundant and adds unnecessary clutter to the source file. Note that subpackages such as java.lang.reflect are not auto-imported and do require explicit imports.
// Bad -- java.lang classes are auto-imported
import java.lang.String;
import java.lang.Integer;
// Good -- no import needed for java.lang classes
// (simply use String, Integer directly)
// OK -- subpackages require explicit import
import java.lang.reflect.Method;
Remediation
Remove the redundant import. The class is available without an explicit import statement.