A single-type-import declaration makes a specific type (class, interface, enum, annotation, or record) from another package available by its simple name within the current compilation unit. It establishes a direct mapping between the fully qualified name (FQN) of the type and its simple name, instructing the compiler to resolve the simple name to the FQN during the compilation phase.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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.
Master Java with Deep Grasping Methodology!Learn More





