| Author |
Anybody know how to use "enum" in Java?
|
Jon Campbell
Greenhorn
Joined: Nov 21, 2006
Posts: 5
|
|
The following code compiles, but I don't have any documentation on how to use the "enum" structure. I cant find any info on it in my books or Sun's language documentation... class Test { enum eone { Plus { int operate(int x) { return ++x;} }, Minus { int operate(int x) { return --x;} } } public static void main (String[] args){ System.out.println("eone="+eone.Plus); } }
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#enums
|
"I'm not back." - Bill Harding, Twister
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
To make the enum really useful, it's missing an abstract method declaration: You can use that enum like a normal class, with Plus and Minus being final static fields of the type eone (in fact that's what it *is*).
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
Have you read Sun's Enum Tutorial?
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
 |
|
|
subject: Anybody know how to use "enum" in Java?
|
|
|