I'm reading the Java 8 specification to better understand the Java language.
Specifically, the Chapter 7 Packages.
However in 7.5.2 7.5.2 Type-Import-on-Demand Declarations I don't understand
the case where we can use TypeName
according to the following syntax:
import PackageOrTypeName . * ;
The specification says:
If the PackageOrTypeName denotes a type (§6.5.4), then the name must be qualified (§6.5.5.2), or a compile-time error occurs.
So I jump to 6.5.4 but the following is very unclear:
If the PackageOrTypeName, Q, occurs in the scope of a type named Q, then the PackageOrTypeName is reclassified as a TypeName. Otherwise, the PackageOrTypeName is reclassified as a PackageName. The meaning of the PackageOrTypeName is the meaning of the reclassified name.
So I can't imagine how to use TypeName
.
Please, can anyone provide me with an example to import types with *
with
TypeName
?
You seem to be forgetting about nested classes. An example would be:
import java.util.Map.*;
Which would import Entry
. It can now be used like this (unqualified):
Entry<String, String> e = ...;
Another way to do this import is:
import java.util.Map.Entry;
Where java.util.Map
is the name of a type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With