This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes static import of enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static import of enums" Watch "static import of enums" New topic
Author

static import of enums

tom mickey
Greenhorn

Joined: Aug 02, 2008
Posts: 9
Hi all,
I am having problems running the example code
at:
http://www.java2s.com/Code/Java/Language-Basics/Javastaticimportenum.htm

I get the following errors while compiling the code:

Can somebody point me what i have done wrong?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4180
    
  21

Put the whole shebang into a package, and import the fully qualified class name for Grade.



Steve
tom mickey
Greenhorn

Joined: Aug 02, 2008
Posts: 9
Thanks Steve.
It works now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38436
    
  23
Look at this Java™ Language Specification page (§7.5) and look for "unnamed package" with ctrl-F. That may tell you why Steve Luke's solution works nicely.
tom mickey
Greenhorn

Joined: Aug 02, 2008
Posts: 9
I guess you are referring to section 7.5 where it states

It is a compile time error to import a type from the unnamed package

Thanks for clarifying, Campell.
Edit:
Ah! yes you are. didn't see those brackets while replying.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38436
    
  23
Yes, that's what I meant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static import of enums