Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using multiple enum

 
andrew burrows
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is exactly what I was trying to get.
Thank you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic