Link to home
Start Free TrialLog in
Avatar of igroove
igroove

asked on

C-like enum in Java?

Is there a C-like 'enum' in Java? Example:

C code:
enum tagType {
  TYPE_NULL = 0,
  TYPE_ONE,
  TYPE_TWO,
  ...
  TYPE_N;
} Type;

I've looked at many java sites and didn't see one.  Is there one? Or do I have to do this:

Java:
public interface tagType {
  final static int NULL = 0;
  final static int ONE = 1;
  final static int TWO = 2;
  ...
  final static int N = n;
}
ASKER CERTIFIED SOLUTION
Avatar of amarshal
amarshal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pwyss
pwyss

no you don't! there's a better soultion:

http://developer.java.sun.com/developer/Books/shiftintojava/page1.html

you get type-saftey and more...