• Post Reply Bookmark Topic Watch Topic
  • New Topic

static enums  RSS feed

 
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys
Attaching a sample code here..

Here any static member(here,normalStaticMember) can be accessed using one of the instances of the class(although its not at all a good practice.But Its possible).But in case of enums which are declared static explicitly,its not allowed by compiler(marked above as not compiled).
Can anybody please explain this behaviour??
Thanks in Advance..
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
normalStaticMember is a static member variable.

But Champions is not a variable, it's a nested class (enums are a special kind of classes).

You cannot access nested classes from an instance of the enclosing class like that. Note that it doesn't matter if the enum is static or not, even if it were not static this would not work.
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it..
Thanks Jesper
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!