A single-static-import declaration imports a specific static member (field, method, or nested type) from a named type into the current compilation unit. This allows the compiler to resolve the imported static member by its simple name rather than requiring its fully qualified type name.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.
Syntax
PackageName.TypeName: The fully qualified name of the class or interface containing the static member.Identifier: The exact simple name of the static field, static method, or static nested type being imported.
Technical Mechanics
- Method Overloading: If the
Identifierrefers to a static method, the declaration imports all overloaded static methods bearing that exact name within the target type. You cannot import a specific method signature; you import the method name. - Accessibility: The targeted static member must be accessible to the importing compilation unit. If the member is
private, or package-private and residing in a different package, a compile-time error occurs. - Scope and Shadowing: The imported static member is introduced into the scope of the compilation unit. However, members declared within the current class (as well as inherited members) take precedence and will shadow the statically imported member.
- Naming Conflicts: If two single-static-import declarations attempt to import fields or nested types with the identical simple name from different types, a compile-time error occurs immediately at the import declaration level. However, Java allows statically importing methods with the same simple name from different types. These imported methods simply overload each other. A compile-time error only occurs for methods if the conflicting imports result in methods with the exact same signature (JLS §7.5.3).
- Placement: The declaration must appear after the
packagedeclaration (if present) and before any top-level type declarations (class,interface,enum,record).
Code Visualization
Master Java with Deep Grasping Methodology!Learn More





