println
is a method belonging to the out
member of the System
class. Without that qualifier, Java has no idea what println
is.
When you do a static import, you can access the members of a class without having to provide the fully-qualified name. So your static import of java.lang.System
lets you access everything that System
has. This means that you can access out
(a PrintWriter
instance) which belongs to System
. But it does not mean that you can access println
directly because that belongs to out
. So you have to tell Java how to get to println
by going through out
first.
Look at it this way. Assume you have the following structure:
MyClass
|
+---Something
| |
| +---- methodOne
| |
| +---- methodTwo
| |
| +---- OtherThing
| |
| +---- otherMethodOne
| |
| +---- otherMethodTwo
+---method
If you did a static import with MyClass.*
:
- You have access to
method()
(Java translates this to MyClass.method()
)
- You have access to
Something
. (Java translates this to MyClass.Something
)
- You do not have raw access to other stuff under
Something
. For example, you cannot simply call methodOne()
because Java will translate that to MyClass.methodOne()
, and there is no method called methodOne()
under MyClass
. That method belongs to Something
, so you can do Something.methodOne()
, or Something.OtherThing.otherMethodOne()
.
If you did a static import with MyClass.Something.*
:
- You have access to
methodOne
. (Java translates this to MyClass.Something.methodOne
)
- You have access to
methodTwo
. (Java translates this to MyClass.Something.methodTwo
)
- You have access to
OtherThing
. (Java translates this to MyClass.Something.OtherThing
)
- You do not have raw access to
otherMethodOne
or otherMethodTwo
; you will need to do OtherThing.otherMethodOne()
or OtherThing.otherMethodTwo()
.
- You do not have access to
method
, because Java translates that to MyClass.Something.method
, and there is no such method in the Something
class.