Reputation: 1805
java.io.Reader.*;
I know that Reader
is a class, not a package.
So, what the above declaration will import?
Upvotes: 0
Views: 135
Reputation: 234795
The declaration:
import java.io.Reader.*;
is an example of a type-import-on-demand declaration. From the Java Language Specification:
A type-import-on-demand declaration allows all accessible types of a named package or type to be imported as needed.
Since java.io.Reader
contains no nested classes or other accessible types, the declaration would simply be ignored.
Note that Java also has an import static
declaration. So
import static java.io.Reader.*;
would be an example of a static-import-on-demand declaration. Again, according to the Java Language Specification:
A static-import-on-demand declaration allows all accessible static members of a named type to be imported as needed.
And since java.io.Reader
also has no accessible static members, the declaration would again be ignored.
Upvotes: 2
Reputation: 73
Statement 1 will include the Reader Class that you can use in your code, as this class is used to read the character stream
Statement 2 will include all the Classes from Reader.* Package ( if it is a package), i am assuming it generic
Upvotes: 1
Reputation: 11121
In the same file you can have both
import java.io.Reader; //Statement 1
import static java.io.Reader.*; //Statement 2
the first one is importing only the class Reader
from package java.io
,
the second one is importing all the static members of class Reader, wich appears to be only
private static final int maxSkipBufferSize = 8192;
so, pretty useless, because being it private you cannot access it from your class, neither for reading nor for modifying
Upvotes: 2