Solved

C-like enum in Java?

Posted on 1997-03-14
2
231 Views
Last Modified: 2012-08-13
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;
}
0
Comment
Question by:igroove
2 Comments
 

Accepted Solution

by:
amarshal earned 20 total points
ID: 1218935
You've already found the answer.  You have to use a series of static variables.

Java's philosphy was based on simplicity.  So to prevent adding more structures to the language, enum and #defines were never included.

In the case of your NULL define, 'null' already exists as a Object pointer without an instance.
0
 

Expert Comment

by:pwyss
ID: 3536332
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...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
Java: How do I open the default windows program for a given file type 3 39
going to wrong jsp page 2 33
how to debug htl and js pages 8 39
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question