The import statements of the form:
import packageName.subPackage.*
is Type-Import-on-Demand Declarations. i.e, the classes or any types from them will be imported only when that type is not available in the scope of current compilation unit.
From example 7.5.2-1 of that JLS section only:
The declaration might be shadowed by a single-type-import declaration of a type whose simple name is Vector; by a type named Vector and declared in the package to which the compilation unit belongs; or any nested classes or interfaces.
So, if you have a class String
in the same package as your class, then using String
in that class, will refer to your class, as java.lang.String
will not be imported. It will only be imported on demand, as shown in example 6.4.1-2 of JLS § 6.4.1 - Shadowing.