• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static import of an enum in Java 1.5?

 
Author
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out. Case closed.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


What did you end up doing? Please share.
 
Barry Burd
Author
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic