| Author |
static import of an enum in Java 1.5?
|
Barry Burd
Author
Ranch Hand
Joined: Jun 18, 2003
Posts: 73
|
|
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?
|
 |
Barry Burd
Author
Ranch Hand
Joined: Jun 18, 2003
Posts: 73
|
|
|
I figured it out. Case closed.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally posted by Barry Burd: I figured it out. Case closed.
What did you end up doing? Please share.
|
 |
Barry Burd
Author
Ranch Hand
Joined: Jun 18, 2003
Posts: 73
|
|
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: 73
|
|
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); } }
|
 |
 |
|
|
subject: static import of an enum in Java 1.5?
|
|
|