package declaration (if one exists) and before any top-level type declarations within the .java source file.
Resolution and Accessibility
The compiler strictly evaluates the FQN provided in the declaration. If the specified type does not exist, or if it lacks the appropriate access modifiers (e.g., attempting to import a package-private type from a different package), the compiler throws an error.
Naming Conflicts and Shadowing
- Import Collisions: It is a compile-time error to declare multiple single-type-imports that resolve to the same simple name but different FQNs.
- Precedence over Import-on-Demand: A single-type-import declaration shadows any type with the identical simple name that is imported via an import-on-demand declaration (e.g.,
import java.util.*;). - Conflict with Local Types: It is a compile-time error if a single-type-import declaration has the same simple name as a top-level type declared within the same compilation unit. The local type does not shadow the import; instead, the compiler rejects the duplicate name definition.
- A type within the
java.langpackage, which the compiler imports implicitly. - A type within the same package as the current compilation unit.
- A type that has already been declared in a previous single-type-import within the same file.
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More





