Re: (Very) basic question about class structure
ChrisW wrote:
Should I ask why it needs to be import static instead of just import,
or is that likely to be beyond the realms of my understanding?
Lothar Kimmeringer wrote:
- import static is a new feature added with Java 1.5.
- With import static you can see that not a class but a
method should be imported - even three months after you
saved five minutes in writing source using this construct.
By the way, what does RTFM stand for?
Are you not allowed to use search-engines? I'm curious - really.
Just enter the abbreviation into the search-field, press the
corresponding search-button and read the result on position 1.
System is a class, not a package.
You really should not seek to avoid writing it. "import static" is for lazy
people. Its best use is for static final constants, not methods.
Static members and methods traditionally are referred to through the class to
which they belong. For example, the output stream System.out is a static
Stream that points to the console. It is different from any other "out"
variable that might be in your code because it belongs to the "System" class.
If you left out the "System" your code would actually be less clear to read.
So I recommend, especially for beginners, that you do not use "import static"
at all.
Read the Sun tutorial about packages, classes and members.
<http://java.sun.com/docs/books/tutorial/java/concepts/index.html>
GIYF.
- Lew