• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import java.*; ????

 
Barry Burd
Author
Ranch Hand
Posts: 118
5
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the following code compile without errors?
import java.*;
class MyClass2 {
}
Since "java" isn't the name of an API package, I should get an error message, right?
The following code gives me error messages when I try to compile it:
import javax.*;
class MyClass2 {
}
What gives?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But both are working well at my side. I am using JBuilder X. I have tried both are working well.
 
Jason Fox
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you figure that java.* isn't a package? Obviously, there are no (public, anyway) classes that reside at that level, but isn't it still considered part of the package (directory) structure? I'm actually not quite sure about this, and would love to hear a more in-depth explanation.
 
Barry Burd
Author
Ranch Hand
Posts: 118
5
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know whether to call "java" a package or not. One way or another, I'm using Java 1.5 beta and in that compiler
import java.*;
gives me no error message. But
import javax.*;
gives me an error message. Is there any reason for me to use the statement "import java.*;" ? Is there anything I can do once I've used it that I can't do (at least not without using fully qualified names) if I
haven't used it?
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thought...
Could this be because of the workaround for the JavaDoc bug where packages that are empty produce no doco at the package level? The 'java' package has package-level doco (ie, the welcome screen on the API, but I don't think the javax package does.
If that's the case, maybe 'import java.*' is allowed because you import one undocumented class with no public constructors, and 'import javax.*' is illegal because there are no classes directly in javax. (That said, is it illegal to import an empty "package", I couldn't work it out from the JLS
Anyway, just a thought - I would have thought that this bug'd be fixed by the release of the 1.5 API, maybe I'll check the bug parade later...

--Tim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic