• Post Reply Bookmark Topic Watch Topic
  • New Topic

import static java.util.* - Error?  RSS feed

 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, I import all classes from java.util package, and it compiles fine.

But when I try to static import the same package, it doesn't work. It gives me the error, error: cannot find symbol


Why I can't use the second code fragment?
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think the "import static" version should be doing?
 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What do you think the "import static" version should be doing?


oh apology, I noticed it just now.

It imports all the static members from the specified location. Inside java.util.* there is no static members. There is only classes. (classes can be static too, but only nested classes)
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only static import from a class, not from a package, so that's why you get the error,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!