aspose file tools*
The moose likes Java in General and the fly likes static import of an enum in Java 1.5? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "static import of an enum in Java 1.5?" Watch "static import of an enum in Java 1.5?" New topic
Author

static import of an enum in Java 1.5?

Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

If I define
enum Scale {Celsius, Fahrenheit, Kelvin, Rakine};
in a file all its own, then I don't seem to be able to do
import static Scale.*;
in any of my other files. Isn't Scale just a class, and aren't the values
of Scale just static members of that class?


Java For Dummies, 6th Edition, Java Programming for Android Developers For Dummies
Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

I figured it out. Case closed.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Barry Burd:
I figured it out. Case closed.

What did you end up doing? Please share.


GenRocket - Experts at Building Test Data
Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

Actually, I **thought** I had figured it out, but that's only because I was compiling the wrong code. In fact, I still don't know what's wrong. I can do a static import when I put the enum in a separate package and I do both
import util.Scale;
import static util.Scale.*;
but I can't do the import when I put the enum class in the default package. I guess this means that, since the original import declaration isn't meant to grab anything from the default package, the static import can't do that either. That's not good.
Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

The problem seems to be with static import for the default package in general, not with enums. For instance, the following code does not compile:
public class Stuff {
public static int i = 7;
}
--------------------...and in another file...
import static Stuff.i;
class UseStuff {
public static void main(String args[]) {
System.out.println(i);
}
}
 
wood burning stoves
 
subject: static import of an enum in Java 1.5?