Avoid Star Import
ID |
kotlin.avoid_star_import |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
code-style, imports |
Description
Reports imports of the form import x.*. Wildcard imports hide which symbols
a file actually uses and can silently introduce collisions when an upstream
library adds new top-level declarations.
Rationale
Explicit imports document the file’s dependency surface, keep code review unambiguous, and let static-analysis tooling reason about which symbols are in scope. Wildcard imports defeat all three.
// Bad
import java.util.*
import kotlin.collections.*
// Good
import java.util.List
import java.util.Map
import kotlin.collections.listOf
Remediation
Replace each wildcard import with explicit imports for every symbol used in the file. Most IDEs offer a one-click "Optimize Imports" action.