• Post Reply Bookmark Topic Watch Topic
  • New Topic

Enum inside an Enum  RSS feed

 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to create an inside an ,

Following is the code i have written:



The code isn't compiling. When i add a Dummy (commented out now) variable it compiles fine. What could be the reason ?

Adithya.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If DataBaseConstants doesn't have any values, there's no point making it an enum. Just make it a class. I'd suggest an abstract class with a private constructor, as you won't want to instantiate it.
 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. You are right. It makes sense too

I have actually created the enum inside a class. So, i will have to create an static abstract class right ?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adithya narayan wrote:Yeah. You are right. It makes sense too

I have actually created the enum inside a class. So, i will have to create an static abstract class right ?

Top level classes aren't static in Java. Abstract, yes (it doesn't have to be, but it makes sense). And as I said, I'd give it a private constructor so you can't subclass it. In fact, if you do that the abstract is unnecessary (though still probably worth leaving in for readability).
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please CarefullyChooseOneForum
 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
adithya narayan wrote:Yeah. You are right. It makes sense too

I have actually created the enum inside a class. So, i will have to create an static abstract class right ?

Top level classes aren't static in Java. Abstract, yes (it doesn't have to be, but it makes sense). And as I said, I'd give it a private constructor so you can't subclass it. In fact, if you do that the abstract is unnecessary (though still probably worth leaving in for readability).


Thanks for your explanation.

When i said i have created the enum inside a class i meant the following:



Here, if i don't declare the DataBaseContants as static it says
The member enum DEALCOMPONENT must be defined inside a static member type
. Hence, i had to declare the abstract class static too ! I could write an outer class too but i wanted to write an inner class.



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