• Post Reply Bookmark Topic Watch Topic
  • New Topic

nested enums  RSS feed

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I nest enums?

I have something like this:




I want to navigate within the nested enums something like:

How can I do that?
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nimo frey wrote:...

How can I do that?


Try it.
Note that the hyphen, -, is illegal in variable names.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks it works as expected

 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nimo frey wrote:thanks it works as expected



No problem.
 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if i remove the instance variables drinks and eats from the code ? The code doesn't compile. Does anyone know the significance of it ?

Adithya.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if I'd have expected that to compile or not, but it doesn't surprise me - what's the point of an enum with no values? You can make Foods a class if you don't need it to have any values.
 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah..that makes sense too
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nimo frey wrote:I want to navigate within the nested enums something like:

Hmmm. I question the usefulness of something like that. Enums are final, so you can't inherit behaviour between them. If there is indeed a relationship between your types, I suspect you'd be far better off using inheritance or (possibly better) composition.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!