wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 4164
    
  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: 37884
    
  22
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: 37884
    
  22
Yes, that's what I meant
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static import of enums
 
Similar Threads
CActus problem
Applet insights?
Array Project Help
Scanner
Range class