This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
import statements are not recursive. It looks for files inside that package(folder), not inside nested packages.
import static net.mindview.util.Print.*;
This implies that Print is a folder not a file. Is Print supposed to be a file in the util folder? If it is a file, adding .* should generate an error. [ March 04, 2006: Message edited by: Rusty Shackleford ]
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Rusty's statement is correct, but it doesn't apply here. You're both thinking of plain old "import", which from the sound of it, Bob understands just fine. This is import static, a new feature introduced in Tiger (Java 5, JDK 1.5). "import static" lets you import the static members of a class into a file, so that within that source file, you can refer to them as if they were defined in the current class. By using "import static ... Print.*", Eckel is making the print() methods inside his Print class available all by their lonesome; because of this import, you can just call "print()" instead of "Print.print()".
If it's not compiling for you, you must be using a pre-Tiger JDK -- i.e., JDK 1.4 or earlier. You probably want to upgrade if you want to follow the examples in this new book!
Originally posted by Bob Beerbower: ...Bruce's import statements compile, mine do not...
As Ernest pointed out, the static import... import static net.mindview.util.Print.*; ...works with an unqualified call of the static method... print("A String.");
But the regular imports... import net.mindview.util.*; ...or... import net.mindview.util.Print; ...require a qualified call... Print.print("A String.");
So... If the static import code is compiling, but the regular import code is not, my guess is that your method calls are simply not specifying the class "Print" in conjunction with the regular imports.
(PS: I just got Eckel's new 4th edition as well. When I saw your post, I downloaded the code to test this. I put it under my java/library directory because that's where my system classpath is pointing -- or so I thought! I've been using this machine for months, and never noticed that my system classpath was set incorrectly. Shows how much I use that setting.) [ March 04, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jun 06, 2001
Ernest, Thanks for explaining it as clearly as you did. I suspected that it had something to do with the static import being handled differently then a normal import. You gave me a very clear explanation of why this is so.