Unused Import
ID |
java.unused_import |
Severity |
low |
Remediation Complexity |
auto_fix |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Java |
Tags |
code-style, unused-code |
Rationale
Unused imports clutter the namespace, slow down IDE indexing, and can confuse readers about the actual dependencies of a class. They typically accumulate over time as code is refactored and references are removed without cleaning up the corresponding imports.
// Bad -- List and Map are never used in this file
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
public class Example {
private ArrayList<String> items = new ArrayList<>();
}
// Good -- only import what you use
import java.util.ArrayList;
public class Example {
private ArrayList<String> items = new ArrayList<>();
}
Remediation
Remove the unused import statements. Most IDEs provide an "Organize Imports" action that handles this automatically.