Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C-like enum in Java?

Posted on 1997-03-14
2
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
amarshal earned 40 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

688 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