File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retro import

 
Paul Keohan
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bunch of classes in a directory without any package references. So the directory contains all the java and class files. If I want to add a package, I go into one of these java files and stick the package reference at the top. Now it won't compile because all the other classes are not in that package (and this class interacts with them): they're not in any package.
How can I compile this class now and eventually add a package to all of the classes? Is there a way to do something like . In other words, import classes that has no package.
Thanks.
Paul
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 1.3 and before you can import classes from a default package by just importing the name of the class like:

I'm really not sure if you can do this:

but you can give it a shot. If that doesn't work you will need to import all the class as in the first import. Note that importing from the default (or nameless) package is not allowed in 1.4 nor should it have ever been allowed. Here is what Sun has to say about the subject:
The compiler now rejects import statements that import a type from the unnamed namespace. Previous versions of the compiler would accept such import declarations, even though they were arguably not allowed by the language (because the type name appearing in the import clause is not in scope). The specification is being clarified to state clearly that you cannot have a simple name in an import statement, nor can you import from the unnamed namespace.
To summarize, the syntax import SimpleName; is no longer legal. Nor is the syntax import ClassInUnnamedNamespace.Nested; which would import a nested class from the unnamed namespace. To fix such problems in your code, move all of the classes from the unnamed namespace into a named namespace.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic