File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Using multiple enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using multiple enum" Watch "Using multiple enum" New topic

Using multiple enum

andrew burrows

Joined: Oct 17, 2008
Posts: 2
Given two enum types (fruit and veg), and an input. How do you find out the enum type from the input?

Here is code for example (the code obviously doesn't work):

I'm thinking either I have to somehow use a general enum type(or cast it), Or I have misunderstood what enumation is about.
[ October 17, 2008: Message edited by: andrew burrows ]
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
The switch you are attempting to you would allow you to discern the element of the enum. So if you did a switch on an instance of fruit, you could use cases of APPLE or ORANGE.

Fruit and Veg are essentially different classes. If you wanted to tell if an Object was a String or an Integer how would you do it? You would use the instanceof operator (also known as Type Comparison operator). The same is true with the fruit and veg.

I'd reccomend having a read of the section of the sun tutorial that gives an introduction to the instanceof operator.
andrew burrows

Joined: Oct 17, 2008
Posts: 2
This is exactly what I was trying to get.
Thank you very much!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Using multiple enum
It's not a secret anymore!